views:

1455

answers:

4

Duplicate:

Why isn’t my javascript & css caching ?

I'm noticing that I'm only receiving 304 HTTP codes (cached content) for images but not JavaScript or CSS.

My .htaccess file is:

Options -Indexes
Options +FollowSymLinks  

# Enable ETag
FileETag MTime Size

# Set expiration header
ExpiresActive on
ExpiresDefault "access plus 1 week"

# Compress some text file types
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml application/x-javascript text/javascript application/javascript application/json

# Deactivate compression for buggy browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# Set header information for proxies
Header append Vary User-Agent

Anyone know why only images are caching and not my JavaScript or CSS?

+2  A: 

Use a snooping proxy like Fiddler to see what the browser is requesting of your server and the headers that are being returned.

You should see an initial request with a "200" status returned. Then you should see a request from the browser to verify its cache. The return header should indicate that the browser cache is still good and should not include the page content.

Chris Nava
+1  A: 

Use Firebug for Firefox, have a look at the network tab. You will not see a network connection for cached content on reload.

Marcus
Wouldn't I still see network connection for cached content BUT, the connection would simply be to verify the local file matches the server copy? I'm using Firebug and see 200 responses back on everything
What concerns me is that I'm receiving 200 responses not 304 (not modified).
200 should be the initial, from then on 304 (not modified). If this is not the case, you'll have to check your server settings.
jvenema
@jvenema - I'm included my server settings now in the description of the post
+1  A: 

I usually use this addon:

https://addons.mozilla.org/en-US/firefox/addon/3829

it lets you monitor the HTTP requests, if the file isn't being requested then its cached. Also if your still having caching issues make sure your not using a funky proxy. (i have ran into issues where the proxy was losing the ETag so it was never caching)

Chad Scira
have someone on another ISP try loading your site. Like i said sometimes proxy's may lose some of the information. Or it could be a browser setting. To test with a browser other than firefox try this program:http://www.charlesproxy.com/download.php
Chad Scira
A: 

I'll use either Firebug or TamperData to monitor HTTP request. The latter is useful in the case where there might be redirects involved, which Firebug won't necessarily tell you.

David
@David - any idea why my JS and CSS are not being cached?