Hello Developers,
I spent half a day pulling my hair out, before I figured out that changes I make to my java scripts do not make it to the browser. The same problem applies to *.css files. It is a well known problem - resources requested by GET are being cached, and changing Response.Cache settings seems to make no impact.
There are some ways around, like adding a unique request parameter, but it is rather inconvenient.
Is there any proven solution which could be implemented on the global application level to allow effective AJAX development, like some tweaking in one of the global events?
I am wondering how ASP.Net Development Team handles this issue.
Thank you for any help.
Tomasz J
Mine normally doen'st cache if I have compilation debug='true' in the config file.
Hi,
Mine apparently does :(
Why would caching be different in debug mode?
Here is what seems to work, but may be there is a better way.
TJ
void Application_PreRequestHandlerExecute(object sender,EventArgs e){HttpContext context =HttpContext.Current;
TimeSpan cacheDuration =TimeSpan.FromSeconds(1);
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetExpires(DateTime.Now.Add(cacheDuration));
context.Response.Cache.SetMaxAge(cacheDuration);
context.Response.Cache.AppendCacheExtension("must-revalidate, proxy-revalidate");
}
There is a setting in the web.config file which caches the javascript file to reduce the downloading of the Ajax Framework scripts also those which are added by the scriptmanager script references. But i think the defaut value is not cache the js files. You try this setting enable/disable caching.
<scriptResourceHandlerenableCompression="true"enableCaching="false"/>
I am not sure about the Css files caching, the default is cached i think and setting response.cache will not make any impact as the css files are handled by IIS instead of Asp.net runtimes unless you sepcify same asp.net handler for css too.
Although I read this setting applies to server caching only, it seems to work, so it probably also modifies the response header and tells the client not to cache.
Thank you for your help. I was unaware of this setting. By default it is commented out.
In VS 2005 dev environment requests to static content (well, at least *.css, *.jpg and *.gifs) go through asp.net. With IIS the story is, or can be different.
Tomasz J
If this tips helps you pls mark it as answer.
No comments:
Post a Comment