Stop browser to make HTTP requests for images that should stay cached - mod_expires

后端 未结 10 1038
猫巷女王i
猫巷女王i 2020-12-04 10:01

After reading many articles and some questions on here, I finally succeded in activating the Apache mod_expires to tell the browser it MUST cache images

10条回答
  •  我在风中等你
    2020-12-04 10:43

    Cache Validation and the 304 response

    There are a number of situations in which Internet Explorer needs to check whether a cached entry is valid:

    • The cached entry has no expiration date and the content is being accessed for the first time in a browser session

    • The cached entry has an expiration date but it has expired

    • The user has requested a page update by clicking the Refresh button or pressing F5

    If the cached entry has a last modification date, IE sends it in the If-Modified-Since header of a GET request message:

    GET /images/logo.gif HTTP/1.1
    Accept: */*
    Referer: http://www.google.com/
    Accept-Encoding: gzip, deflate
    If-Modified-Since: Thu, 23 Sep 2004 17:42:04 GMT
    User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;)
    Host: www.google.com
    

    The server checks the If-Modified-Since header and responds accordingly. If the content has not been changed since the date/time specified, it replies with a status code of 304 and a response message that just contains headers:

    HTTP/1.1 304 Not Modified
    Content-Type: text/html
    Server: GWS/2.1
    Content-Length: 0
    Date: Thu, 04 Oct 2004 12:00:00 GMT
    

    The response can be quickly downloaded because it contains no content and causes IE to read the data it requires from the cache. In effect, it is like a redirection to the local browser cache.

    If the requested object has actually changed since the date/time in the If-Modified-Since header, the server responses with a status code of 200 and supplies the modified version of the resource.

提交回复
热议问题