How to use browser cache in node.js?

My site runs on a node.js server, and when I test my site on the Google Page Rendering Tool, it shows me how to use the browser cache. I searched a lot on the Internet, but so far no luck. If anyone knows how to use browser cache in node.js, please let me know.

+5
source share
1 answer

The browser cache is mainly controlled by the user, outside the control of Node. The only thing you can really do is set the max-age header for static files served by Node.js.

Assuming you are using express, cache the file in one day:

app.use(express.static(__dirname + '/public', { maxAge: 86400000 })); 
+7
source

Source: https://habr.com/ru/post/1211645/


All Articles