0

We have an asp.net mvc 5 application, In this application for each page it has its own JavaScript files. Most of the times these scripts files are changed and the changes aren't portrayed at client side because of caching, due to which we have to tell the users to press Ctrl+F5 to refresh the page otherwise the script files are served from cache. I searched and find multiple solutions, In most of the solution it was writing an HTML helper and then replacing all js files references at each page/view with the helper function. This approach is a hectic job, because we have atleast 300 pages/views. Now my question is. Is there a way in IIS or any other way, that without doing any change at code level if script file is changed at server, it will not serve the file from cache.

Tanzeel ur Rehman
  • 429
  • 2
  • 6
  • 18
  • Are you using the default Bundler? It should handle this situation. – Jasen Jan 18 '16 at 18:58
  • I am using bundling, for all those scripts that are shared among pages, as i stated above that more than 300 pages, every page having its own JavaScript reposing domain for the page. so page level scripts are not in the bundling. – Tanzeel ur Rehman Jan 18 '16 at 21:54
  • Perhaps you could find a scheme to group and bundle page scripts (by Areas perhaps) then load area scripts for your pages rather than a single script. You could also use a [cache buster](http://stackoverflow.com/questions/9692665/cache-busting-via-params) on your script url but that would require code to generate the url. – Jasen Jan 18 '16 at 21:59
  • Thanks @Jasen. This solution is good but it needs changes to the query string value when there is a change in the script. – Tanzeel ur Rehman Jan 18 '16 at 22:04
  • Even if you managed to use cache-control headers in IIS or with your app, the browser could freely ignore them and continue to serve the cached resource. – Jasen Jan 18 '16 at 22:04
  • I suppose you could automate the build so you get a version number each time you rebuild then have your Helper extract and append that value when you write out the src attribute. – Jasen Jan 18 '16 at 22:05

0 Answers0