views:

161

answers:

4

I want to verify that the images, css, and javascript files that are part of my page are being cached by my browser. I've used Fiddler and Google Page Speed and it's unclear whether either is giving me the information I need. Fiddler shows the HTTP 304 response for images, css, and javascript which should tell the browser to use the cached copy. Google Page Speed shows the 304 response but doesn't show a Transfer Size of Zero, instead it shows the full file size of the resource. Note also, I have seen Google Page Speed report a 200 response but then put the word (cache) next to the 200 (so Status is 200 (cache)), which doesnt make a lot of sense.

Any other suggestions as to how I can verify whether the server is sending back images, css, javascript after they've been retrieved and cached by a previous page hit?

+3  A: 

In browser HTTP debuggers are probably the easiest to use in your situation. Try HTTPFox for Firefox or Opera which has dragonfly built-in. Both of these indicate when the local browser cache has been used.

If you appear to be getting conflicting information, then wireshark/tcpdump will show you if the objects are being downloaded or not as it is monitoring the actual network packets being transmitted and received. If you haven't looked at network traces before, this might be a little confusing at first.

ar
Trying out HTTPFox but cant find it's documentation. For resources that result in a 304 Response, it shows Received file size as (XXX) e.g. (1134); for a 200 Response it doesnt have parenthesis e.g. 1134. Do the parenthesis indicate that it's cached locally and the file isnt in fact transferred?
BestPractices
Yes, of course. The 304 response doesn't *have* a body to list the size of.
hobbs
+2  A: 

In fiddler, check out that the response body (for images, css) is empty. Also make sure your max-age is long enough in Cache-Control header. Most browsers (Safari, Firefox) have good traffic analyzer tools.

jholster
So it will make the request again, but just respond with an empty response? I thought the browser wouldn't re-request the resource if it has been cached.
Merritt
It makes the request again-- it's up to the server to tell the browser whether the resource has not been modified (by giving it a 304 Response). Looks something like this: HTTP/1.1 304 Not ModifiedDate: Wed, 24 Mar 2010 14:51:02 GMT. X-Powered-By: Servlet/2.5 JSP/2.1
BestPractices
The client may use the cached copy and not make new request until the expiration of _max-age_ or _Expires_ headers, after which it may ask the server if the file is still unchanged (If-Modified-Since). Other caching mechanisms exist as well, e.g. Etag. See http://www.mnot.net/cache_docs/ and http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
jholster
A: 

A HTTP/304 response is forbidden to have a body. Hence, the full-response isn't sent, instead you just get back the headers of the 304 response. But the round-trip itself isn't free, and hence sending proper expiration information is a good practice to improve performance to avoid making the conditional request that returns the 304 in the first place.

http://www.fiddler2.com/redir/?id=httpperf explains this topic in some detail.

EricLaw -MSFT-
+1  A: 

Your servers access logs can give you a lot of information on how effective your caching strategy is.

Lets say you have a html page /home.html, which references /some.js and /lookandfeel.css. For a given time period, aggregate the number of requests to all three files.

If your caching is effective, you should see a huge number of requests for home.html, but very few for the css or js. Somewhere in between is when you see identical number of requests for all 3, but the css and js have 304s. The worst is when you are only seeing 200s.

Obviously, you have to know your application to do such a study. The js and css files may be shared across multiple pages - which may complicate your analysis. But the general idea still holds good.

The advantage of such a study is that you can find out how effective your caching strategy is for your users as opposed to 'Is caching working on my machine'. However, this is no substitute for using a http proxy / fiddler.

sri
Useful suggestion-- thanks!
BestPractices