Browser cache

The process of browser cache

    1. The browser fetch the content in http://www.patrickcai.com for the first time
    2. The server return the content with the two kinds of headers

Firstly ,the header should tell the browser when to fetch the content from the server instead of getting it from the web cache

  1. Expires: Fri, 05 Jul 2002, 05:00:00 GMT
  2. Cache-Control: max-age=484200

The max age is counted as seconds ,so only after 484200 seconds should the browser fetch the content from the server .

Secondly,when the browser cache expires, the client send the request with corresponding header which tell the server to compare the content in cache and server.There are two methods,comparing etag and modified time

  1. etag:""2a276f-59cd-50c0f857695a7""
    etags are like the version number for the document,once the document is updated, the egags will also be updated.
  2. Last-modified: "Wed, 07 Jan 2015 13:01:26 GMT"

 

  1. Next time, when the browser again trys to fetch the content in the same url.There are two situtations
    1. The cache has not expired yet, the client get the content from the browser cache
    2. The cache has expired, the client send the request with headers
      1. If-Modified-Since:<date> the data comes from Last-modified
      2. If-None-Match: <tags> tags come from the etag
  2. The server compares the date and etags ,if the document has not been updated, the server will send the 304 Not modified status code and empty body entity.