0

I'm trying to set my images to cache. With no settings, I'm getting a 304 response from the server, which means that while 100 requests are being made for each of my images, the image isn't actually being transferred.

Great.

Now I want to tell the browser to use the image from cache without making the request to see if it was modified.

I go into IIS7 and click on the folder with my images, select the HTTP Response Headers and click Set Common Headers.

On the dialog the apears I check off the "Expire Web Content" box and I select the "After" option and I select 1 Day(I also tried 2 days).

I click OK and run a iisreset (although I don't think this is nessesary). I open up internet explorer with the network tab active and load the page. The browser loads the images. They are 200 responses and I check the headers and find "Cache-Control:max-age=172800" Great.

Now I reload the page (clicking on a link that loads the same page, or clicking in the address bar and pressing enter... NOT clicking refresh) and check the network tab again. I'm still getting 304 repsonses from the server, the browser is not directly loading the image from cache.

What do I need to do to get the browser to load this from cache?

Note: This works correctly in Chrome (Of course, story of my life)

Note2: Someone noted that sometime IE says 304 even though it is really going strait to cache. I don't see it going through Fiddler, HOWEVER, I see in the network tab of IE9 it is saying the Response time is 327 milliseconds. This time seems to increase for the images that are loaded later. So out of the 100 images the first 10 had respnses between 16-70 ms and the last 10 had responses of over 800 ms. The one that took 327ms was somewhere in the middle. Is IE really this inefficient retrieving from the cache?

Also, I should note there are files, such as some css files, that IE says are 304, however the response time is <1ms, which I'm assuming means it actually got it from cache without going over the network. That's different than this case for my images where IE actually shows a response time of hundreds of milliseconds.

kralco626
  • 7,896
  • 36
  • 104
  • 165
  • Use fiddler and make sure all dev tools are disabled in your browser. I noticed yesterday that Chrome will do different things depending on if your dev tools are enabled or not. Also, make sure there is no vary header. Vary headers can mess with WinInet proxy caching. – Darrel Miller Feb 12 '14 at 14:04
  • hmm, OK I'll try this. It does work correctly in chrome, even with the dev tools open. But I'll use fiddler to see what IE is doing when I turn the dev tools off. – kralco626 Feb 12 '14 at 14:06
  • It is interesting because I did a similar test yesterday with Chrome and found when the dev tools was open and I did a .ajax request the max-age was ignored and it did a request that returned 304. When I closed the dev tools it didn't make the request at all. – Darrel Miller Feb 12 '14 at 14:11
  • hum, maybe it is different with ajax requests? Or because mine are images? It is not making the request for me, I can see the (from cache) when I load the page. If I click the "refresh" button as opposed to clicking a link that loads the page or clicking in the address bar and clicking enter chrome does make the request and get the 304 response. Are you sure in your case you were not clicking refresh? – kralco626 Feb 12 '14 at 14:13
  • No I wasn't clicking refresh. I created a link specifically to navigate to the same page. However, it was a script link that I was seeing the behaviour on. Can you remove the last-modified/etag header from the image, that will stop the browser from doing a conditional request? – Darrel Miller Feb 12 '14 at 14:16
  • So I tried with fiddler running. When IE9 was making the request that got a 304 response, nothing showed up on fiddler. When Chrome got the 304 it DID show up on fiddler. I know that IE9 is making the requests because I see it in the network tab and I can tell based on how long the page is taking to load, it would stop spinning a lot faster if it wasn't held up getting the 304 responses for .9 seconds. – kralco626 Feb 12 '14 at 14:21
  • I can remove that header, I don't know how though. – kralco626 Feb 12 '14 at 14:21
  • Well I can't edit my previous comment, but I used the drag and drop target to tell fiddler to target IE for logging and I do see that IE is getting the 304 responses even when I have the developer tools off. So, I still have the question... why is IE not respecting the max age header. – kralco626 Feb 12 '14 at 14:28
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/47328/discussion-between-darrel-miller-and-kralco626) – Darrel Miller Feb 12 '14 at 14:33
  • The IE developer tools show a 304 even when the cache got hit, see here: http://stackoverflow.com/questions/8936284/browser-caching-why-does-ie9-always-show-http-304-when-actually-it-did-not-hit . If the request doesn't show up in Fiddler, it wasn't sent across the network. – Alexander Köplinger Feb 12 '14 at 16:17
  • That's interesting, because I don't see it going through Fiddler, HOWEVER, I see in the network tab of IE9 it is saying the Response time is 327 milliseconds. This time seems to increase for the images that are loaded later. So out of the 100 images the first 10 had respnses between 16-70 ms and the last 10 had responses of over 800 ms. The one that took 327ms was somewhere in the middle. Is IE really this inefficient retrieving from the cache? – kralco626 Feb 12 '14 at 16:25
  • Also, I should note, that there are files, such as some css files that IE says are 304s, however the response time is <1ms, which I'm assuming means it actually got it from cache. Thats different than this case where IE actually shows a response time. – kralco626 Feb 12 '14 at 16:44
  • How big are the images and are you on an HDD? Maybe disk IO is slowing down the cache. – Alexander Köplinger Feb 12 '14 at 18:19
  • images are about 50KB and I'm on a laptop with 100% SSD. – kralco626 Feb 13 '14 at 15:13

0 Answers0