I tried the following, but the expiration is set to 1 minute:
app.get(['/css/*','/js/*'],express.static('public',{maxAge:7*86400000}));
app.get(['/fonts/*'],express.static('public',{maxAge:30*86400000}));
How do set the expiration time using ExpressJS? In the code above, I tried setting the expiration time to 1 week and 1 month respectively.
You use Express static, and it's perfecly fine, it's rather powerfull tool to serve static files.
express.static is the only built-in middleware in Express. It is based on serve-static, and is responsible for serving the static assets of an Express application.
Besides maxage support it also supports ETags.
Just use it this way:
app.use(express.static(__dirname + '/public', { maxAge: '1d' }));
Here is the very good explanation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With