Why are browsers not caching these static files?

2019-09-18 06:25发布

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.

标签: http browser
1条回答
Fickle 薄情
2楼-- · 2019-09-18 07:02

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.

查看更多
登录 后发表回答