Merge pull request #5431 from NodeBB/ajaxify-cache-buster

Ajaxify improvements, `/assets/uploads/` fixes, cache buster improvements
v1.18.x
Julian Lam 8 years ago committed by GitHub
commit 8bf719b258

@ -249,48 +249,37 @@ $(document).ready(function () {
$(window).trigger('action:script.load', data); $(window).trigger('action:script.load', data);
// Require and parse modules // Require and parse modules
var outstanding = 0; var outstanding = data.scripts.length;
var onReady = function () {
if (outstanding) {
return setTimeout(onReady, 100);
}
data.scripts = data.scripts.filter(Boolean);
data.scripts.forEach(function (functionRef) {
functionRef();
});
callback(); data.scripts.map(function (script) {
if (typeof script === 'function') {
return function (next) {
script();
next();
}; };
}
data.scripts.forEach(function (script, idx) { if (typeof script === 'string') {
switch (typeof script) { return function (next) {
case 'string':
++outstanding;
(function (idx) {
require([script], function (script) { require([script], function (script) {
if (script && script.init) { if (script && script.init) {
data.scripts[idx] = script.init; script.init();
} else {
data.scripts[idx] = null;
} }
--outstanding; next();
}, function () {
// ignore 404 error
next();
}); });
}(idx)); };
break; }
return null;
case 'function': }).filter(Boolean).forEach(function (fn) {
// No changes needed fn(function () {
break; outstanding -= 1;
if (outstanding === 0) {
default: callback();
// Neither? No comprende
data.scripts[idx] = undefined;
break;
} }
}); });
});
onReady();
}; };
ajaxify.loadData = function (url, callback) { ajaxify.loadData = function (url, callback) {

@ -365,7 +365,7 @@ Controllers.handle404 = function (req, res) {
if (isClientScript.test(req.url)) { if (isClientScript.test(req.url)) {
res.type('text/javascript').status(200).send(''); res.type('text/javascript').status(200).send('');
} else if (req.path.startsWith(relativePath + '/uploads') || (req.get('accept') && req.get('accept').indexOf('text/html') === -1) || req.path === '/favicon.ico') { } else if (req.path.startsWith(relativePath + '/assets/uploads') || (req.get('accept') && req.get('accept').indexOf('text/html') === -1) || req.path === '/favicon.ico') {
meta.errors.log404(req.path || ''); meta.errors.log404(req.path || '');
res.sendStatus(404); res.sendStatus(404);
} else if (req.accepts('html')) { } else if (req.accepts('html')) {

@ -32,15 +32,15 @@ exports.read = function read(callback) {
fs.readFile(filePath, function (err, buffer) { fs.readFile(filePath, function (err, buffer) {
if (err) { if (err) {
winston.warn('[cache-buster] could not read cache buster: ' + err.message); winston.warn('[cache-buster] could not read cache buster: ' + err.message);
return callback(); return callback(null, generate());
} }
buffer = buffer.toString(); if (!buffer || buffer.toString().length !== 11) {
if (buffer) { winston.warn('[cache-buster] cache buster string invalid: expected /[a-z0-9]{11}/, got `' + buffer + '`');
cached = buffer; return callback(null, generate());
return callback(null, cached);
} }
callback(); cached = buffer.toString();
callback(null, cached);
}); });
}; };

Loading…
Cancel
Save