Fix cache busting for systemjs imports for plugins

* everything imported via systemjs in the path `plugin/` will get a
 timestamp appended for cache busting
* timestamp is set once on page load
* plugin css loader gets cache buster too
This commit is contained in:
David Kaltschmidt
2018-05-29 12:01:10 +02:00
parent 2d5ec9b9e4
commit 8bcd55d221
2 changed files with 22 additions and 23 deletions

View File

@ -1,6 +1,7 @@
"use strict";
if (typeof window !== 'undefined') {
var bust = '?_cache=' + Date.now();
var waitSeconds = 100;
var head = document.getElementsByTagName('head')[0];
@ -13,8 +14,8 @@ if (typeof window !== 'undefined') {
}
var isWebkit = !!window.navigator.userAgent.match(/AppleWebKit\/([^ ;]*)/);
var webkitLoadCheck = function(link, callback) {
setTimeout(function() {
var webkitLoadCheck = function (link, callback) {
setTimeout(function () {
for (var i = 0; i < document.styleSheets.length; i++) {
var sheet = document.styleSheets[i];
if (sheet.href === link.href) {
@ -25,17 +26,17 @@ if (typeof window !== 'undefined') {
}, 10);
};
var noop = function() {};
var noop = function () { };
var loadCSS = function(url) {
return new Promise(function(resolve, reject) {
var timeout = setTimeout(function() {
var loadCSS = function (url) {
return new Promise(function (resolve, reject) {
var timeout = setTimeout(function () {
reject('Unable to load CSS');
}, waitSeconds * 1000);
var _callback = function(error) {
var _callback = function (error) {
clearTimeout(timeout);
link.onload = link.onerror = noop;
setTimeout(function() {
setTimeout(function () {
if (error) {
reject(error);
}
@ -47,22 +48,22 @@ if (typeof window !== 'undefined') {
var link = document.createElement('link');
link.type = 'text/css';
link.rel = 'stylesheet';
link.href = url;
link.href = url + bust;
if (!isWebkit) {
link.onload = function() {
link.onload = function () {
_callback();
}
} else {
webkitLoadCheck(link, _callback);
}
link.onerror = function(event) {
link.onerror = function (event) {
_callback(event.error || new Error('Error loading CSS file.'));
};
head.appendChild(link);
});
};
exports.fetch = function(load) {
exports.fetch = function (load) {
// dont reload styles loaded in the head
for (var i = 0; i < linkHrefs.length; i++)
if (load.address == linkHrefs[i])