how to solve the JavaScript caching issues using etags or any other ways.


by saravanan.

  • What JavaScript caching issues..? danwellman almost 7 years ago

1 answer


If your pages are being generated dynamically (PHP, Rails etc.), you can add a random query string to the end of your script src:

<script type="text/javascript" src="scripts/myscript.js?315724"></script>

It'll make no difference to the rest of your code, but the browser will see the URL is different and request the script again. If you view source on this page you'll notice this technique has been used on one of the scripts and one of the CSS files.

Answered almost 7 years ago by Rob Crowther
  • You're assuming he doesn't want the JS to be cached. When I read it, I assumed the opposite. Doug almost 7 years ago
  • Yep, because caching of JS is what happens by default if you don't do anything. Rob Crowther almost 7 years ago