Prevent scripts from being cached programmatically?

You should be able to use HttpContext.Current.Response.Cache. SetCacheability(HttpCacheability. NoCache) 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 system.

Web> Open(Server. MapPath("~/script/TheScript. Js"), FileMode.

Open)) scriptStream. CopyTo(context.Response. OutputStream); context.Response.End(); } public bool IsReusable { get { return false; } } } }.

You should be able to use HttpContext.Current.Response.Cache. SetCacheability(HttpCacheability. NoCache); 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: namespace skmHttpHandlers { public class JavascriptHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.Clear(); context.Response.Cache.

SetCacheability(HttpCacheability. NoCache) using (var scriptStream = File. Open(Server.

MapPath("~/script/TheScript. Js"), FileMode. Open)) scriptStream.

CopyTo(context.Response. OutputStream); context.Response.End(); } public bool IsReusable { get { return false; } } } }.

Thanks for the answer. I'm new to HttpHandlers. I'm searching on how to render script using that, but no luck.

Can you show me a sample code? – KaeL Feb 22 at 2:33 Have a look at this page: msdn.microsoft. Com/en-us/library/ms972953.

Aspx – Magnus Feb 22 at 8:18 Thanks Magnus for the codes. I'll be looking into this and post my updates after testing this. :) – KaeL Feb 22 at 10:28 I tested this one but firefox still doesn't update the script.

Here is my code (I'm not 100% sure if I'm doing the right thing, but I was able to render the script using HttpHandler). – KaeL Feb 23 at 8:04 @Web. Config: – KaeL Feb 23 at 8:04.

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.

Thanks for the answer. :D I've already tried this one (querystring) and it solves the caching issue, but i'm looking for a more programmatic way if there is any, like setting it from code behind. – KaeL Feb 21 at 7:49 You can alwyas use RegisterClientScriptBlock from codebehind and than add the Ticks – Magnus Feb 21 at 8:16 @Magnus: What I mean is if there are any other options rather than using querystring which I can set from code behind.

^_^ – KaeL Feb 21 at 8:36.

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 technet.microsoft.com/en-us/library/cc73....

I've already come up with HttpHeader configuration at IIS, but we have issues in controlling IIS in our Production Site. But definitely this will work. Thanks!

:D – KaeL Feb 24 at 1:19.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions