adding cache busters to client side files (closed #586)

v1.18.x
Julian Lam 11 years ago
parent 0f254c0b6c
commit 43c05d1d85

@ -6,7 +6,7 @@
<link rel="icon" type="image/x-icon" href="{brand:favicon}" /> <link rel="icon" type="image/x-icon" href="{brand:favicon}" />
<link href="{cssSrc}" rel="stylesheet" media="screen"> <link href="{cssSrc}" rel="stylesheet" media="screen">
<link rel="stylesheet" href="{relative_path}/vendor/fontawesome/css/font-awesome.min.css"> <link rel="stylesheet" href="{relative_path}/vendor/fontawesome/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="{relative_path}/css/theme.css" /> <link rel="stylesheet" type="text/css" href="{relative_path}/css/theme.css{cache-buster}" />
{link_tags} {link_tags}
<!-- BEGIN pluginCSS --> <!-- BEGIN pluginCSS -->
<link rel="stylesheet" href="{pluginCSS.path}"> <link rel="stylesheet" href="{pluginCSS.path}">

@ -236,11 +236,18 @@ var fs = require('fs'),
callback(null, [path.relative(path.join(__dirname, '../public'), Meta.js.minFile)]); callback(null, [path.relative(path.join(__dirname, '../public'), Meta.js.minFile)]);
} else { } else {
Meta.js.minify(function () { Meta.js.minify(function () {
callback(null, [path.relative(path.join(__dirname, '../public'), Meta.js.minFile)]); callback(null, [
path.relative(path.join(__dirname, '../public'), Meta.js.minFile) + (meta.config['cache-buster'] ? '?v=' + meta.config['cache-buster'] : '')
]);
}); });
} }
}); });
} else { } else {
if (meta.config['cache-buster']) {
scripts = scripts.map(function(script) {
return script + '?v=' + meta.config['cache-buster'];
});
}
callback(null, scripts); callback(null, scripts);
} }
}); });

@ -85,7 +85,7 @@ var path = require('path'),
linkTags = utils.buildLinkTags(defaultLinkTags.concat(options.linkTags || [])), linkTags = utils.buildLinkTags(defaultLinkTags.concat(options.linkTags || [])),
templateValues = { templateValues = {
cssSrc: meta.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css', cssSrc: meta.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css',
pluginCSS: plugins.cssFiles.map(function(file) { return { path: file }; }), pluginCSS: plugins.cssFiles.map(function(file) { return { path: file + (meta.config['cache-buster'] ? '?v=' + meta.config['cache-buster'] : '') }; }),
title: meta.config.title || '', title: meta.config.title || '',
description: meta.config.description || '', description: meta.config.description || '',
'brand:logo': meta.config['brand:logo'] || '', 'brand:logo': meta.config['brand:logo'] || '',
@ -97,7 +97,8 @@ var path = require('path'),
meta_tags: metaString, meta_tags: metaString,
link_tags: linkTags, link_tags: linkTags,
clientScripts: clientScripts, clientScripts: clientScripts,
navigation: custom_header.navigation navigation: custom_header.navigation,
'cache-buster': meta.config['cache-buster'] ? '?v=' + meta.config['cache-buster'] : ''
}; };
var uid = '0'; var uid = '0';
@ -124,6 +125,23 @@ var path = require('path'),
app.enable('minification'); app.enable('minification');
} }
// Configure cache-buster timestamp
require('child_process').exec('git describe --tags', {
cwd: path.join(__dirname, '../')
}, function(err, stdOut) {
if (!err) {
meta.config['cache-buster'] = stdOut.trim();
if (global.env === 'development') {
winston.info('[init] Cache buster value set to: ' + stdOut);
}
} else {
if (global.env === 'development') {
winston.warn('[init] Cache buster not set');
}
}
});
// Middlewares // Middlewares
app.configure(function() { app.configure(function() {
async.series([ async.series([

Loading…
Cancel
Save