perf: lazy load svg sprictes on websites

This commit is contained in:
David 2024-06-11 19:34:20 +02:00
parent c146ea24b6
commit 37d8e2bb36
No known key found for this signature in database
GPG key ID: AB15A6AF1101390D
3 changed files with 15 additions and 4 deletions

View file

@ -43,8 +43,11 @@ doctype_js = {
}
web_include_js = ["website_script.js"]
web_include_css = []
web_include_icons = [
"frappe/icons/timeless/icons.svg",
"frappe/icons/espresso/icons.svg",
]
email_css = ["email.bundle.css"]

View file

@ -44,6 +44,7 @@
<script>
window.frappe = {};
window._version_number = "{{ build_version }}";
frappe.ready_events = [];
frappe.ready = function(fn) {
frappe.ready_events.push(fn);
@ -54,8 +55,6 @@
</script>
</head>
<body frappe-session-status="{{ 'logged-in' if frappe.session.user != 'Guest' else 'logged-out'}}" data-path="{{ path | e }}" {%- if template and template.endswith('.md') %} frappe-content-type="markdown" {%- endif %} class="{{ body_class or ''}}">
{% include "public/icons/timeless/icons.svg" %}
{% include "public/icons/espresso/icons.svg" %}
{%- block banner -%}
{% include "templates/includes/banner_extension.html" ignore missing %}
@ -90,10 +89,19 @@
{% block base_scripts %}
<!-- js should be loaded in body! -->
<div id="all-symbols" style="display:none"></div>
<script>
frappe.boot = {{ boot }}
// for backward compatibility of some libs
frappe.sys_defaults = frappe.boot.sysdefaults;
{%- for path in web_include_icons -%}
fetch(`/assets/{{ path }}?v=${window._version_number}`, {credentials: "same-origin"})
.then((r) => r.text())
.then((svg) => {
let svg_container = document.getElementById("all-symbols");
svg_container.insertAdjacentHTML("beforeend", svg);
});
{%- endfor -%}
</script>
{{ include_script('frappe-web.bundle.js') }}
{% endblock %}

View file

@ -229,8 +229,8 @@ def get_website_settings(context=None):
context.encoded_title = quote(encode(context.title or ""), "")
context.web_include_js = hooks.web_include_js or []
context.web_include_css = hooks.web_include_css or []
context.web_include_icons = hooks.web_include_icons or []
via_hooks = hooks.website_context or []
for key in via_hooks: