0

i am using below cache control lines in jsp

response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.setDateHeader("Expires", 0);

but still my javascript files are getting cached to the disk. does this prevents caching of only JSP or also JS files? is there any other way to avoid caching of javascript files to disk? Please help me out of this Thanks you

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531

1 Answers1

2

It only disables cache for your JSP page, because javascript/images are loaded with separate HTTP requests (that will not have those headers you're setting). You need to look into you web server's config. Another option is adding a ?version=X to your javascripts' URL (X being timestamp if you want to prevent all caching or source control revision number if just want users to get latest production files).

pfyod
  • 617
  • 5
  • 11
  • The answer is correct. You should set the cache configuration in your web server configuration ([Apache for example](http://httpd.apache.org/docs/2.2/caching.html)). – Adrian B. Apr 18 '13 at 11:29
  • Thank you so much i am using sun webserver to test the app.any suggestion to disable the caching of js files on this server. – user2026311 Apr 18 '13 at 11:42
  • Take a look [here](http://stackoverflow.com/questions/10854522/how-to-disable-caching-of-static-assets-like-css-and-js-in-jsf2/10854623#10854623). – pfyod Apr 18 '13 at 12:25