How to disable cache in Xampp and NodeJs Server

abdxzi

Abdul Azeez V

Posted on June 7, 2024

How to disable cache in Xampp and NodeJs Server

When developing frontend sometimes i use NodeJs and Xampp as servers. Sometimes Caching of static files becomes a problem such as styles dont update even though the css files are modified. So i needed to disable the caching.

XAMPP Server

xampp

Edit httpd.conf ([xampp folder]/apache/conf/http.conf) file and add following at the end:



# Don't cache html, htm, js, css

<filesMatch "\.(html|htm|js|css)$">
  FileETag None
  <ifModule mod_headers.c>
     Header unset ETag
     Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
     Header set Pragma "no-cache"
     Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
  </ifModule>
</filesMatch>


Enter fullscreen mode Exit fullscreen mode

NodeJS Server

Use nocache module.



pnpm i nocache


Enter fullscreen mode Exit fullscreen mode


const nocache = require('nocache');
app.use(nocache());


Enter fullscreen mode Exit fullscreen mode

OR

Use set etag to false



app.set('etag', false);


Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
abdxzi
Abdul Azeez V

Posted on June 7, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related