fix: Add version tag for non-bundled assets
This commit is contained in:
parent
895d68f41d
commit
13e04999d2
1 changed files with 27 additions and 13 deletions
|
|
@ -124,20 +124,34 @@ frappe.assets = {
|
|||
// this is virtual page load, only get the the source
|
||||
// *without* the template
|
||||
|
||||
let itemsProcessed = 0;
|
||||
if (items.length) frappe.dom.freeze();
|
||||
if (items.length === 0) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
items.forEach((item, idx) => {
|
||||
fetch(item)
|
||||
.then((r) => r.text())
|
||||
.then((body) => {
|
||||
frappe.assets.add(item, body);
|
||||
itemsProcessed++;
|
||||
if (itemsProcessed === items.length) {
|
||||
frappe.dom.unfreeze();
|
||||
callback();
|
||||
}
|
||||
});
|
||||
const versionString = frappe.boot.developer_mode
|
||||
? Date.now()
|
||||
: frappe.boot.metadata_version;
|
||||
|
||||
async function fetchItem(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);
|
||||
}
|
||||
// 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 body = await response.text();
|
||||
frappe.assets.add(item, body);
|
||||
}
|
||||
|
||||
frappe.dom.freeze();
|
||||
const fetchPromises = items.map(fetchItem);
|
||||
Promise.all(fetchPromises).then(() => {
|
||||
frappe.dom.unfreeze();
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue