-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I set different max-age for different types of file? #32
Comments
That is a good question :) There are two main methods for doing this: Method 1You keep your js/css/images/etc. in different sub folders. For example, perhaps you keep everything in var serveStatic = require('serve-static')
app.use('/templates', serveStatic(__dirname + '/public/templates', { maxAge: 0 }))
app.use(serveStatic(__dirname + '/public'), { maxAge: '1y' }) Method 2Your files are all inter-mingled and you want to apply the 0 max age to all files that are var mime = require('mime-types')
var serveStatic = require('serve-static')
app.use(serveStatic(__dirname + '/public', {
maxAge: '1y',
setHeaders: function (res, path) {
if (mime.lookup(path) === 'text/html') {
res.setHeader('Cache-Control', 'public, max-age=0')
}
}
})) |
Exactly what I want. |
I tried what you said @dougwilson , but the last one is the one getting set:
All my resources are with max-age=9000 (last line). What am I missing? @gfaceless it worked for you? |
Unless your URLs are |
That's true @dougwilson , my bad. sorry. |
running the first suggestion now results in a type error.
|
Hi there,
I'm using version footprint to manage my static assets (js/css/images), I would like to give html files
max-age:0
, and give all other assetsmax-age:'365d'
Currently I'm doing this by writing my own middleware, is there a way to do it using serve-static? maybe some filter function?
The text was updated successfully, but these errors were encountered: