开发者

Can browser display objects from its cache without receiving a 304 status code?

I'm trying to understand if is it possible to avoid request for some embedded objects, 开发者_JS百科loading them directly from cache without asking to web server if the object is valid or not (i don't want web server response to me with 304 http status code) Is it possible ? Does the expire header works for this way? How?


Of course: Request:

<script scr="my_js.php"></script> 

Response:

<? header("HTTP/1.1 304 Not Modified");
header("Expires: Mon, 31 Dec 2035 12:00:00 gmt");
header("Cache-Control: max-age=".(60*60*24*365)); 
echo "//this is a simpe example"; ?>

Solved

Browser loads resources from his cache without asking them to the web server only the first time you open the page (new tab or new browser window).

The other times browser ALWAYS ask information to the server about the resources saved in his cache. Then, the web server response with 200 or 301.


Yes, setting a distant expiry header and the asset will not be downloaded again until that expiry.

If you remove the Last-Modified and ETag header, you will totally eliminate If-Modified-Since and If-None-Match requests and their 304 Not Modified Responses, so a file will stay cached without checking for updates until the Expires header indicates new content is available!

Source.


From my htaccess ...

<IfModule mod_headers.c>

    Header unset Pragma
    FileETag None
    Header unset ETag

    # cache images/pdf docs for 10 days
    <FilesMatch "\.(ico|pdf|jpg|jpeg|png|gif|js)$">

      Header set Expires "Mon, 31 Dec 2035 12:00:00 gmt"
      Header unset ETag  
      Header unset Last-Modified

    </FilesMatch>

    # cache html/htm/xml/txt diles for 2 days
    <FilesMatch "\.(html|htm|xml|txt|xsl)$">
      Header set Cache-Control "max-age=7200, must-revalidate"
    </FilesMatch>

</IfModule>

it seems doesn't works .... for example firebug's net panel show me always 200 status code and access.log file report me that external objects are always requested by the browser.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜