views:

246

answers:

5

I am working on a asp.net web site, like normal user, we use asp.net developer server during coding and testing. Today, I found the firefox not cache any static file of my site, since our application is pretty big, it made page load time very slow. I checked firefox about:cache, all the static file cache setting looks like

           Key: http://localhost:26851/App_Layout/icons/actions/email/folder.png
     Data size: 871 bytes
   Fetch count: 1
 Last modified: 2010-08-19 11:59:46
       Expires: 1969-12-31 16:00:00

           Key: http://localhost:26851/Framework/ScriptLibrary/JQueryPlugins/ui.mouse.js
     Data size: 5079 bytes
   Fetch count: 1
 Last modified: 2010-08-19 11:59:39
       Expires: 1969-12-31 16:00:00

FireBug shows header like this

Server  ASP.NET Development Server/9.0.0.0
Date    Thu, 19 Aug 2010 22:10:27 GMT
X-AspNet-Version    2.0.50727
Cache-Control   public
Etag    "1CB3F32C834A880"
Content-Type    text/css
Content-Length  1775
Connection  Close

Firebug has another tab called "cache", the information is:

Last Modified   Thu Aug 19 2010 15:10:27 GMT-0700 (Pacific Daylight Time)
Last Fetched    Thu Aug 19 2010 15:10:27 GMT-0700 (Pacific Daylight Time)
Expires Wed Dec 31 1969 16:00:00 GMT-0800 (Pacific Standard Time)
Data Size   1775
Fetch Count 10
Device  disk

The expires date is set back to 1969-12-31, I believe that's the reason why they are loaded very time. I am using Visual studio 2008, windows 7 machine. The application works fine in IE, the contents are properly cached.

Did anybody see this behavior before?

A: 

ASP.net Dev Sever

According to my running of Fiddler2, it caches the files, ie 304s(Not Modified) responses are done

  • ScriptResource.axd
  • WebResource.axd

Same behanviour occurs in both IE 8 and FF 3.6.8 IE8 has to be set to Automatically check for new versions of a page for this to occur.


IIS

Running it on IIS causes both FF and IE to cache static content.


This caching is due to the webserver adding a last-modified header to the response.

You can get fiddler to listen to localhost by using localhost. instead ( http://weblogs.asp.net/asptest/archive/2008/08/13/tip-on-using-fiddler-with-cassini-and-localhost.aspx ).

mikek3332002
how to check the setting?
Russel Yang
browser.cache.check_doc_frequency has default value 3. And localhost worked fine before when I was using XP.
Russel Yang
Mode 3 seems to be the same as IEs check for a new version automatically. http://kb.mozillazine.org/Browser.cache.check_doc_frequency
mikek3332002
+4  A: 

You need to issue Expires header to make Firefox cache the files.

Otherwise, how do you think it could guess for how long does it need to cache the files?

sanmai
This is the correct answer. No "Expires" header is your problem.
CantSleepAgain
If I create a new project, everything works fine. the problem is it worked before without adding expires header. I am having problem with static content (gif, css). once I move to production site, we can set the expires in IIS. I do not think hard code the expires is a good idea. I suspect something has changed in window 7 or latest firefox.
Russel Yang
A: 

you can try adding one of these to your page load function -

option 1

        Response.ClearHeaders();
        Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1
        Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1
        Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1
        Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1
        Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1 
        Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1 
        Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1 
        Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1 
        Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1 
        Response.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); // HTTP 1.1

option 2

Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1))
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Cache.SetNoStore()
Vinay B R
@Russel Yang - any updates on this answer. i am using this in one of my web apps and haven't seen any issues. if u r facing any issues with this code please do let me know so that i can try out ur scenario and update my application as well
Vinay B R
I believe this will work. I just do not understand why Firefox did not cache the static files. IE 7 works without any problem (access the same asp.net server). and it worked before without adding response header. I noticed this string behavior after I switched to Window 7 and Firefox 3.6.8
Russel Yang
A: 

You could also host the page on your local IIS WebServer instead of running it in the VS Development Server. In IIS you can specify the expiration header settings to your needs.

SimonW
My site works in IIS without any problem. you know the asp.net developer server give an easier debug experience.
Russel Yang
+1  A: 

Thanks everybody for helping this question. I believe I found the reason why FireFox seems very slow on window 7 box. I did not notice the slowness when I was using windows XP.

First all, Firefox will NOT cache any resource from asp.net web developer server. this fact does not change in XP or Window 7. When I use firebug check the resource downloading today, I noticed DNS lookup takes a couple of seconds. then I found out for window 7 default installation, the HOSTS file under windows\system32\driver\etc does not DNS entry 127.0.0.1 localhost. By adding this line to HOSTS file. my site is as fast as before.

Russel Yang