From b5d0169ca74470b62fcf0b3c5f548251b8a59d00 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sat, 23 Sep 2023 15:04:31 +0530 Subject: [PATCH] refactor: fetch logic - Use _version_number which indicates when assets.json was generated. Files are evicted roughly at same time. metadata_version changes with other changes too. - use `includes` instead of index check - camelCase -> snake_case - dont force caching. doesn't seem to be required. Caches without this header too. --- frappe/public/js/frappe/assets.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/frappe/public/js/frappe/assets.js b/frappe/public/js/frappe/assets.js index 6e5f38e394..98b025ebea 100644 --- a/frappe/public/js/frappe/assets.js +++ b/frappe/public/js/frappe/assets.js @@ -129,27 +129,24 @@ frappe.assets = { return; } - const versionString = frappe.boot.developer_mode - ? Date.now() - : frappe.boot.metadata_version; + const version_string = + frappe.boot.developer_mode || window.dev_server ? Date.now() : window._version_number; - async function fetchItem(item) { + async function fetch_item(item) { // Add the version to the URL to bust the cache for non-bundled assets let url = new URL(item, window.location.origin); - if (item.indexOf(".bundle.") === -1 && !url.searchParams.get("v")) { - url.searchParams.append("v", versionString); + if (!item.includes(".bundle.") && !url.searchParams.get("v")) { + url.searchParams.append("v", version_string); } - // Force use cache because we are already busting the cache with the version - const headers = { cache: "force-cache" }; - const response = await fetch(url.toString(), headers); + const response = await fetch(url.toString()); const body = await response.text(); frappe.assets.add(item, body); } frappe.dom.freeze(); - const fetchPromises = items.map(fetchItem); - Promise.all(fetchPromises).then(() => { + const fetch_promises = items.map(fetch_item); + Promise.all(fetch_promises).then(() => { frappe.dom.unfreeze(); callback(); });