I would like to ask if there is a way to prevent Firefox from caching scripts (.js files).
I have a project (ASP.Net Web App) with caching issue on firefox. When I first run the application (script is being cached on firefox) and modify the script and rerun the application, firefox is using the cached script instead of the updated one.
I'm using Firefox 3.6.13.
I already tried using HttpHeaders but it seems like firefox is ignoring my codes.
Here is my code:
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetAllowResponseInBrowserHistory(false);
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
HttpContext.Current.Response.Cache.SetNoStore();
I tried placing this code at global.asax > Application_BeginRequest and at MasterPage.aspx.cs > Page_Load, but it isn't working.
Thanks in advance.
You should be able to use
but you will have to have a http handler that renders the script directly to the response stream and than set the source url of the script tag to the handler or configure IIS to handle all javascripts using a specific handler: Point *.js to the aspnet_isapi.dll ISAPI Extension and than add the following in your web.config
And than the handler:
One technique is to add a random element to the URL as a querystring, so the browser doesn't know how to cache the script:
Even better would be to append the current build number of your assembly, so you get the performance benefits of script caching while the script hasn't changed. This only works however, if you never change your script files "out of band" with your binary releases.
1) Install IIS module: http://www.iis.net/download/urlrewrite
2) Put this in web.config into section:
3) Write this helper function (into some global class)
4) Instead of:
Use:
I WANT the scripts and the styles to be cached... only reload them when they change... It is easy using the date of the file:
If you have control over the IIS configuration then you can put all your scripts inside one folder and tell IIS to expire the content immediately, or add other custom headers of your choice.
The appropriate page for IIS 6.0 is http://technet.microsoft.com/en-us/library/cc732442.aspx