Created
June 8, 2017 20:09
-
-
Save hakimelek/68a689ab32f56e57bc6dcbc8d61825eb to your computer and use it in GitHub Desktop.
Set cache control for assets except html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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