Search code examples
node.jsexpresscache-control

How does Express.js handle Cache-Control automatically?


I was going to use a 'cache buster' to add a hash to the end of static js and css files during grunt build. I don't know too much about cache control. Without doing anything Express.js was sending a 304 status code. If I modified the file then Express.js would send the new file. It seems like I don't need to do anything and it works as expected.

Do I need to implement Cache-Control? Is it already handled auto magically?


Solution

  • Yes, express handles cache-control automatically. It's default value is set to true. And you can just handle it by increasing/decreasing it's maxAge property value. (in milliseconds). Or you can turn this option on or off by setting cacheControl to true or false .

    For more Reference you can refer : Express Documentation