perf: send boot string instead of JSON literal

changes:

- compact boot info in /app HTML
    /app size went from 451kb to 393kb - ~13% less
    Verified that regex applied on this JSON aren't affecting perf, infact
    found them to be faster with compact JSON.

- Send json string instead of placing JSON literal in code using Jinja.
  JS takes more time to pass object literal than parsing a plain JSON string.

Overall content transfer size remains roughly same (albeit slightly
lower) since double escaping ends up adding extra `\` around quotes.

Co-authored-by: Suraj Shetty <surajshetty3416@gmail.com>
This commit is contained in:
Ankush Menat 2022-06-18 22:20:49 +05:30 committed by Suraj Shetty
parent d7fe7ae39c
commit d6f2d34bf4
2 changed files with 4 additions and 2 deletions

View file

@ -42,7 +42,7 @@
if (!window.frappe) window.frappe = {};
frappe.boot = {{ boot }};
frappe.boot = JSON.parse({{ boot }});
frappe._messages = frappe.boot["__messages"];
frappe.csrf_token = "{{ csrf_token }}";
</script>

View file

@ -2,6 +2,7 @@
# License: MIT. See LICENSE
no_cache = 1
import json
import os
import re
@ -32,13 +33,14 @@ def get_context(context):
frappe.db.commit()
boot_json = frappe.as_json(boot)
boot_json = frappe.as_json(boot, indent=None, separators=(",", ":"))
# remove script tags from boot
boot_json = SCRIPT_TAG_PATTERN.sub("", boot_json)
# TODO: Find better fix
boot_json = CLOSING_SCRIPT_TAG_PATTERN.sub("", boot_json)
boot_json = json.dumps(boot_json)
context.update(
{