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

Thanks

by saravanan.

  • What JavaScript caching issues..? danwellman over 6 years ago

1 answer

1
point

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 over 6 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 over 6 years ago
  • Yep, because caching of JS is what happens by default if you don't do anything. Rob Crowther over 6 years ago