DEV Community

Abdul Azeez V
Abdul Azeez V

Posted on

1

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

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay