How can I set different max-age for different types of file?
See original GitHub issueHi 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 assets max-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?
Issue Analytics
- State:
- Created 9 years ago
- Reactions:7
- Comments:6 (2 by maintainers)
Top Results From Across the Web
node.js - Express - Setting different maxAge for certain files
My problem is that if I set maxAge, my index.html file gets cached and the first request to '/' doesn't go through router...
Read more >Set max-age headers for specific pages, files, or paths
You normally set this by using the UI by navigating to Admin > Configuration > Development > Performance on Drupal 7 and entering...
Read more >Access-Control-Max-Age - HTTP - MDN Web Docs
The Access-Control-Max-Age response header indicates how long the results of a preflight request (that is ... Header type, Response header.
Read more >Express serve-static middleware
This example shows how to set a different max age depending on the served file type. In this example, HTML files are not...
Read more >Server-side caching - Apollo GraphQL Docs
You can set a default maxAge that's applied to fields that otherwise receive the default maxAge of 0 . You should identify and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That is a good question 😃 There are two main methods for doing this:
Method 1
You keep your js/css/images/etc. in different sub folders. For example, perhaps you keep everything in
public/
, except your html files are inpublic/templates/
. In this case, you can split it by path:Method 2
Your files are all inter-mingled and you want to apply the 0 max age to all files that are
text/html
. In this case, you need to add a header setting filter: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?