Skip to content

Instantly share code, notes, and snippets.

@hakimelek
Created June 8, 2017 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakimelek/68a689ab32f56e57bc6dcbc8d61825eb to your computer and use it in GitHub Desktop.
Save hakimelek/68a689ab32f56e57bc6dcbc8d61825eb to your computer and use it in GitHub Desktop.
Set cache control for assets except html
if (process.env.NODE_ENV === 'production') {
app.use('/drive/search/public', express.static(__dirname + '/../public'), {
maxAge: '1d',
setHeaders: setCustomCacheControl
});
} else {
app.use('/drive/search/public', express.static(__dirname + '/../client/src'));
}
function setCustomCacheControl (res, path) {
if (serveStatic.mime.lookup(path) === 'text/html') {
// Custom Cache-Control for HTML files
res.setHeader('Cache-Control', 'public, max-age=0');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment