diff --git a/frappe/hooks.py b/frappe/hooks.py index 7a97b3ece8..74c3a7a974 100644 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -33,8 +33,8 @@ app_include_css = [ "report.bundle.css", ] app_include_icons = [ - "frappe/icons/timeless/icons.svg", - "frappe/icons/espresso/icons.svg", + "/assets/frappe/icons/timeless/icons.svg", + "/assets/frappe/icons/espresso/icons.svg", ] doctype_js = { @@ -45,8 +45,8 @@ doctype_js = { web_include_js = ["website_script.js"] web_include_css = [] web_include_icons = [ - "frappe/icons/timeless/icons.svg", - "frappe/icons/espresso/icons.svg", + "/assets/frappe/icons/timeless/icons.svg", + "/assets/frappe/icons/espresso/icons.svg", ] email_css = ["email.bundle.css"] diff --git a/frappe/templates/base.html b/frappe/templates/base.html index 375f80e8c2..efde1ea594 100644 --- a/frappe/templates/base.html +++ b/frappe/templates/base.html @@ -87,21 +87,17 @@ ) }} {%- endblock -%} + + {%- for path in web_include_icons -%} + {{ include_icons(path) }} + {%- endfor -%} + {% block base_scripts %} - {{ include_script('frappe-web.bundle.js') }} {% endblock %} diff --git a/frappe/utils/jinja_globals.py b/frappe/utils/jinja_globals.py index 848f41c527..37b3a2c962 100644 --- a/frappe/utils/jinja_globals.py +++ b/frappe/utils/jinja_globals.py @@ -110,6 +110,25 @@ def include_script(path, preload=True): return f'' +def include_icons(path, preload=True): + """Get path of bundled svg icons files. + + If preload is specified the path will be added to preload headers so browsers can prefetch + assets.""" + path = bundled_asset(path) + + if preload: + import frappe + + frappe.local.preload_assets["icons"].append(path) + + return ( + '' + ) + + def include_style(path, rtl=None, preload=True): """Get path of bundled style files. diff --git a/frappe/website/utils.py b/frappe/website/utils.py index 0e4916023e..38d78c4aea 100644 --- a/frappe/website/utils.py +++ b/frappe/website/utils.py @@ -573,7 +573,7 @@ def add_preload_for_bundled_assets(response): version = get_build_version() links.extend( - f"; rel=preload; as=fetch; crossorigin" + f"<{svg}?v={version}>; rel=preload; as=fetch; crossorigin" for svg in frappe.local.preload_assets["icons"] ) diff --git a/frappe/www/app.html b/frappe/www/app.html index a2fef3362d..d9534be770 100644 --- a/frappe/www/app.html +++ b/frappe/www/app.html @@ -21,7 +21,7 @@ href="{{ favicon or "/assets/frappe/images/frappe-favicon.svg" }}" type="image/x-icon"> - {% for include in include_css -%} + {% for include in app_include_css -%} {{ include_style(include) }} {%- endfor -%} @@ -56,17 +56,13 @@ frappe.csrf_token = "{{ csrf_token }}"; - {%- for path in 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 -%} - {% for include in include_js %} + {%- for path in app_include_icons -%} + {{ include_icons(path) }} + {%- endfor -%} + + {% for include in app_include_js %} {{ include_script(include) }} {% endfor %} diff --git a/frappe/www/app.py b/frappe/www/app.py index 9fe9628f53..5f27c0cf01 100644 --- a/frappe/www/app.py +++ b/frappe/www/app.py @@ -46,21 +46,20 @@ def get_context(context): boot_json = json.dumps(boot_json) hooks = frappe.get_hooks() - include_js = hooks.get("app_include_js", []) + frappe.conf.get("app_include_js", []) - include_css = hooks.get("app_include_css", []) + frappe.conf.get("app_include_css", []) - include_icons = hooks.get("app_include_icons", []) - frappe.local.preload_assets["icons"].extend(include_icons) + app_include_js = hooks.get("app_include_js", []) + frappe.conf.get("app_include_js", []) + app_include_css = hooks.get("app_include_css", []) + frappe.conf.get("app_include_css", []) + app_include_icons = hooks.get("app_include_icons", []) if frappe.get_system_settings("enable_telemetry") and os.getenv("FRAPPE_SENTRY_DSN"): - include_js.append("sentry.bundle.js") + app_include_js.append("sentry.bundle.js") context.update( { "no_cache": 1, "build_version": frappe.utils.get_build_version(), - "include_js": include_js, - "include_css": include_css, - "include_icons": include_icons, + "app_include_js": app_include_js, + "app_include_css": app_include_css, + "app_include_icons": app_include_icons, "layout_direction": "rtl" if is_rtl() else "ltr", "lang": frappe.local.lang, "sounds": hooks["sounds"],