Prevent Caching of Script Service AJAX calls – the lazy way
Nicolas Galler | February 20, 2008“REST” style AJAX calls can be cached by the browser if the server is not properly configured. For some services this is a good thing (think, a mapping service), but often it is a hassle.
The way I see it there are 3 ways to get around it:
- The “proper” way is to configure the caching on the server app. For example in ASP.NET use Response.Cache.SetCacheability(HttpCacheability.NoCache), or use the <%@ OutputCache %> tag.
- The “fix it from the client” way is to add a random parameter to the Javascript. This way the query is different every time. If the server can accept POST as well as GET you can also use a POST since those are not cached.
- The “lazy” way is to force a header from the server configuration. In IIS this is super easy:
- edit the properties of the directory that contains your script services
- go to HTTP Headers
- Add a custom header: name is “Cache-Control” and value is “no-cache”





