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 = {};
|
||||
running = {};
|
||||
worker = new Worker(`/code/worker.js`);
|
||||
worker = new Worker(`/code/worker.js?${exports.VERSION}`);
|
||||
|
||||
worker.onmessage = function(e) {
|
||||
let now = time(),
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
/** Copyright Stewart Allen -- All Rights Reserved */
|
||||
"use strict";
|
||||
|
||||
importScripts(`/code/work.js`);
|
||||
importScripts(`/code/work.js${location.search}`);
|
||||
|
||||
let loc = self.location,
|
||||
ver = exports.VERSION,
|
||||
let ver = exports.VERSION,
|
||||
base = self.base,
|
||||
moto = self.moto,
|
||||
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
|
||||
* @returns {String}
|
||||
|
|
@ -186,7 +171,7 @@ function concatCode(array) {
|
|||
let code = [ `(function() { let load = [ `];
|
||||
array.forEach(file => {
|
||||
if (file.indexOf(".js") < 0) {
|
||||
file = `/js/${file}.js`;
|
||||
file = `/js/${file}.js?${ver.VERSION}`;
|
||||
}
|
||||
if (file.indexOf(":\\") > 0) {
|
||||
file = `/${file}`;
|
||||
|
|
@ -326,6 +311,26 @@ function limit(array, length, timespan, inc) {
|
|||
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} res
|
||||
|
|
@ -1306,6 +1311,7 @@ handler.use(fullpath({
|
|||
.use(handleDebug)
|
||||
.use(fixedmap("/api/", api))
|
||||
.use(compression)
|
||||
.use(rewrite)
|
||||
.use(handleStatic(currentDir + "/web/"))
|
||||
.use(reply404)
|
||||
.listen(port)
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@
|
|||
<title>Kiri:Moto</title>
|
||||
<link rel="icon" href="/kiri/favicon.ico">
|
||||
<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="/kiri/style.css?181">
|
||||
<script src="/code/kiri.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/moto/style.css?{{version}}">
|
||||
<link rel="stylesheet" type="text/css" href="/kiri/style.css?{{version}}">
|
||||
<script src="/code/kiri.js?{{version}}"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- app title home page links -->
|
||||
|
|
|
|||
Loading…
Reference in a new issue