0

Here's an example JavaScript file request/response:

Request URL:http://local/index.js?time=1367958844038
Request Method:GET
Status Code:200 OK

Request Headers
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
DNT:1
User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31

Response Headers
cache-control:max-age=31536000
content-encoding:gzip
content-type:application/javascript
expires:Wed, 07 May 2014 20:34:04 GMT
last-modified:Tue, 07 May 2013 20:34:04 GMT
transfer-encoding:chunked

As you can see, the server responds with cache control, expires and even last modified, but everytime I reload with either F5 or clicking enter in location bar the request looks the same (I'd expect browser to send if-modified-since, etc.)

This happens in Chrome and Firefox at least.

Ahmed
  • 1,669
  • 4
  • 14
  • 16

1 Answers1

1

Probably because the URL's time parameter changes with every request.

Since the URL is different, the browser can't use the previously cached response.

josh3736
  • 139,160
  • 33
  • 216
  • 263
  • Actually the time is the same. I just noticed that requesting the file directly is using the cache! But when loaded from the page it's not doing that. – Ahmed May 07 '13 at 21:18
  • Actually it seems to be cached! But the browser doesn't do a if-modified-since and the server returns 200 OK, but still it's being fetched from the cache. – Ahmed May 07 '13 at 21:25
  • The dev tools are lying to you (or at least, they're very misleading). When you see a request with `Status Code: 200 OK (from cache)`, it means the browser *didn't even issue* a conditional HTTP request. It just grabbed the content from cache -- no network activity at all. If you use something like Fiddler, you wouldn't even see the request. – josh3736 May 07 '13 at 21:46