add cache buster through intercepted text rewrite
This commit is contained in:
parent
460cbea747
commit
279f2ad0b3
4 changed files with 28 additions and 23 deletions
|
|
@ -49,7 +49,7 @@ KIRI.work = {
|
||||||
|
|
||||||
slicing = {};
|
slicing = {};
|
||||||
running = {};
|
running = {};
|
||||||
worker = new Worker(`/code/worker.js`);
|
worker = new Worker(`/code/worker.js?${exports.VERSION}`);
|
||||||
|
|
||||||
worker.onmessage = function(e) {
|
worker.onmessage = function(e) {
|
||||||
let now = time(),
|
let now = time(),
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
/** Copyright Stewart Allen -- All Rights Reserved */
|
/** Copyright Stewart Allen -- All Rights Reserved */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
importScripts(`/code/work.js`);
|
importScripts(`/code/work.js${location.search}`);
|
||||||
|
|
||||||
let loc = self.location,
|
let ver = exports.VERSION,
|
||||||
ver = exports.VERSION,
|
|
||||||
base = self.base,
|
base = self.base,
|
||||||
moto = self.moto,
|
moto = self.moto,
|
||||||
util = base.util,
|
util = base.util,
|
||||||
|
|
|
||||||
|
|
@ -155,21 +155,6 @@ function prepareScripts() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {String} name
|
|
||||||
* @oaram {Array} list
|
|
||||||
* @returns {String}
|
|
||||||
*/
|
|
||||||
function htmlScript(prefix, list) {
|
|
||||||
let code = [];
|
|
||||||
|
|
||||||
list.forEach(file => {
|
|
||||||
code.push('\t<script src="/' + prefix + file + '.js/' + ver.VERSION + '"></script>');
|
|
||||||
});
|
|
||||||
|
|
||||||
return code.join("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Array} array
|
* @param {Array} array
|
||||||
* @returns {String}
|
* @returns {String}
|
||||||
|
|
@ -186,7 +171,7 @@ function concatCode(array) {
|
||||||
let code = [ `(function() { let load = [ `];
|
let code = [ `(function() { let load = [ `];
|
||||||
array.forEach(file => {
|
array.forEach(file => {
|
||||||
if (file.indexOf(".js") < 0) {
|
if (file.indexOf(".js") < 0) {
|
||||||
file = `/js/${file}.js`;
|
file = `/js/${file}.js?${ver.VERSION}`;
|
||||||
}
|
}
|
||||||
if (file.indexOf(":\\") > 0) {
|
if (file.indexOf(":\\") > 0) {
|
||||||
file = `/${file}`;
|
file = `/${file}`;
|
||||||
|
|
@ -326,6 +311,26 @@ function limit(array, length, timespan, inc) {
|
||||||
return limit;
|
return limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function rewrite(req, res, next) {
|
||||||
|
if (req.url.indexOf(".html") > 0) {
|
||||||
|
let real_write = res.write;
|
||||||
|
let real_end = res.end;
|
||||||
|
|
||||||
|
res.write = function() {
|
||||||
|
arguments[0] = arguments[0].toString().replace(/{{version}}/g,ver.VERSION);
|
||||||
|
real_write.apply(res, arguments);
|
||||||
|
};
|
||||||
|
res.end = function() {
|
||||||
|
if (arguments[0]) {
|
||||||
|
arguments[0] = arguments[0].toString().replace(/{{version}}/g,ver.VERSION);
|
||||||
|
}
|
||||||
|
real_end.apply(res, arguments);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} req
|
* @param {Object} req
|
||||||
* @param {Object} res
|
* @param {Object} res
|
||||||
|
|
@ -1306,6 +1311,7 @@ handler.use(fullpath({
|
||||||
.use(handleDebug)
|
.use(handleDebug)
|
||||||
.use(fixedmap("/api/", api))
|
.use(fixedmap("/api/", api))
|
||||||
.use(compression)
|
.use(compression)
|
||||||
|
.use(rewrite)
|
||||||
.use(handleStatic(currentDir + "/web/"))
|
.use(handleStatic(currentDir + "/web/"))
|
||||||
.use(reply404)
|
.use(reply404)
|
||||||
.listen(port)
|
.listen(port)
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,9 @@
|
||||||
<title>Kiri:Moto</title>
|
<title>Kiri:Moto</title>
|
||||||
<link rel="icon" href="/kiri/favicon.ico">
|
<link rel="icon" href="/kiri/favicon.ico">
|
||||||
<link rel="apple-touch-icon" href="/kiri/favicon-mobile.png">
|
<link rel="apple-touch-icon" href="/kiri/favicon-mobile.png">
|
||||||
<link rel="stylesheet" type="text/css" href="/moto/style.css?181">
|
<link rel="stylesheet" type="text/css" href="/moto/style.css?{{version}}">
|
||||||
<link rel="stylesheet" type="text/css" href="/kiri/style.css?181">
|
<link rel="stylesheet" type="text/css" href="/kiri/style.css?{{version}}">
|
||||||
<script src="/code/kiri.js"></script>
|
<script src="/code/kiri.js?{{version}}"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<!-- app title home page links -->
|
<!-- app title home page links -->
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue