mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #12096 from grafana/davkal/11446-fix-systemjs-cachebust
Fix cache busting for systemjs imports for plugins
This commit is contained in:
commit
40844614bf
@ -27,6 +27,13 @@ import 'rxjs/add/observable/from';
|
|||||||
import 'rxjs/add/operator/map';
|
import 'rxjs/add/operator/map';
|
||||||
import 'rxjs/add/operator/combineAll';
|
import 'rxjs/add/operator/combineAll';
|
||||||
|
|
||||||
|
// add cache busting
|
||||||
|
const bust = `?_cache=${Date.now()}`;
|
||||||
|
function locate(load) {
|
||||||
|
return load.address + bust;
|
||||||
|
}
|
||||||
|
System.registry.set('plugin-loader', System.newModule({ locate: locate }));
|
||||||
|
|
||||||
System.config({
|
System.config({
|
||||||
baseURL: 'public',
|
baseURL: 'public',
|
||||||
defaultExtension: 'js',
|
defaultExtension: 'js',
|
||||||
@ -40,23 +47,14 @@ System.config({
|
|||||||
css: 'vendor/plugin-css/css.js',
|
css: 'vendor/plugin-css/css.js',
|
||||||
},
|
},
|
||||||
meta: {
|
meta: {
|
||||||
'*': {
|
'plugin*': {
|
||||||
esModule: true,
|
esModule: true,
|
||||||
authorization: true,
|
authorization: true,
|
||||||
|
loader: 'plugin-loader',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// add cache busting
|
|
||||||
var systemLocate = System.locate;
|
|
||||||
System.cacheBust = '?bust=' + Date.now();
|
|
||||||
System.locate = function(load) {
|
|
||||||
var System = this;
|
|
||||||
return Promise.resolve(systemLocate.call(this, load)).then(function(address) {
|
|
||||||
return address + System.cacheBust;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function exposeToPlugin(name: string, component: any) {
|
function exposeToPlugin(name: string, component: any) {
|
||||||
System.registerDynamic(name, [], true, function(require, exports, module) {
|
System.registerDynamic(name, [], true, function(require, exports, module) {
|
||||||
module.exports = component;
|
module.exports = component;
|
||||||
|
25
public/vendor/plugin-css/css.js
vendored
25
public/vendor/plugin-css/css.js
vendored
@ -1,6 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
|
var bust = '?_cache=' + Date.now();
|
||||||
var waitSeconds = 100;
|
var waitSeconds = 100;
|
||||||
|
|
||||||
var head = document.getElementsByTagName('head')[0];
|
var head = document.getElementsByTagName('head')[0];
|
||||||
@ -13,8 +14,8 @@ if (typeof window !== 'undefined') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var isWebkit = !!window.navigator.userAgent.match(/AppleWebKit\/([^ ;]*)/);
|
var isWebkit = !!window.navigator.userAgent.match(/AppleWebKit\/([^ ;]*)/);
|
||||||
var webkitLoadCheck = function(link, callback) {
|
var webkitLoadCheck = function (link, callback) {
|
||||||
setTimeout(function() {
|
setTimeout(function () {
|
||||||
for (var i = 0; i < document.styleSheets.length; i++) {
|
for (var i = 0; i < document.styleSheets.length; i++) {
|
||||||
var sheet = document.styleSheets[i];
|
var sheet = document.styleSheets[i];
|
||||||
if (sheet.href === link.href) {
|
if (sheet.href === link.href) {
|
||||||
@ -25,17 +26,17 @@ if (typeof window !== 'undefined') {
|
|||||||
}, 10);
|
}, 10);
|
||||||
};
|
};
|
||||||
|
|
||||||
var noop = function() {};
|
var noop = function () { };
|
||||||
|
|
||||||
var loadCSS = function(url) {
|
var loadCSS = function (url) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
var timeout = setTimeout(function() {
|
var timeout = setTimeout(function () {
|
||||||
reject('Unable to load CSS');
|
reject('Unable to load CSS');
|
||||||
}, waitSeconds * 1000);
|
}, waitSeconds * 1000);
|
||||||
var _callback = function(error) {
|
var _callback = function (error) {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
link.onload = link.onerror = noop;
|
link.onload = link.onerror = noop;
|
||||||
setTimeout(function() {
|
setTimeout(function () {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
}
|
}
|
||||||
@ -47,22 +48,22 @@ if (typeof window !== 'undefined') {
|
|||||||
var link = document.createElement('link');
|
var link = document.createElement('link');
|
||||||
link.type = 'text/css';
|
link.type = 'text/css';
|
||||||
link.rel = 'stylesheet';
|
link.rel = 'stylesheet';
|
||||||
link.href = url;
|
link.href = url + bust;
|
||||||
if (!isWebkit) {
|
if (!isWebkit) {
|
||||||
link.onload = function() {
|
link.onload = function () {
|
||||||
_callback();
|
_callback();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
webkitLoadCheck(link, _callback);
|
webkitLoadCheck(link, _callback);
|
||||||
}
|
}
|
||||||
link.onerror = function(event) {
|
link.onerror = function (event) {
|
||||||
_callback(event.error || new Error('Error loading CSS file.'));
|
_callback(event.error || new Error('Error loading CSS file.'));
|
||||||
};
|
};
|
||||||
head.appendChild(link);
|
head.appendChild(link);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.fetch = function(load) {
|
exports.fetch = function (load) {
|
||||||
// dont reload styles loaded in the head
|
// dont reload styles loaded in the head
|
||||||
for (var i = 0; i < linkHrefs.length; i++)
|
for (var i = 0; i < linkHrefs.length; i++)
|
||||||
if (load.address == linkHrefs[i])
|
if (load.address == linkHrefs[i])
|
||||||
|
Loading…
Reference in New Issue
Block a user