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:
parent
d7fe7ae39c
commit
d6f2d34bf4
2 changed files with 4 additions and 2 deletions
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue