Browser caching

Browser caching has been taken for granted for so long, that I had not had an opportunity to explore it. Recently, I went through it for leveraging the cache of the browser and I want to put together the findings here :

    Expiration caching -
        The browser caches contents of a page (with the key as the url) for a predefined amount of time, which is indicated in the HTTP Response headers. After this time the browser sends a request to the server, to check for fresh contents.

     Validation caching -
          With HTTP 1.1 a new tag called the Entity Tag (ETag) is introduced, which is opaque to the browser (i.e., just stored by the browser). The browser does not do anything with the ETag but just sends the value as "If-None-Match" HTTP Request header. The server can utilize the ETag by sending a value which identifies the contents of a page, for instance, the userId so that the cache is valid for the user's session. On receiving the ETag value in the "If-None-Match" header, the server can validate whether the contents in the browser cache are still valid, for instance, now the server knows that the user has logged out, and so the cache is invalid, and the fresh contents can be sent back.

    The typical steps involved are : 

  1. The browser caches contents of a page if the HTTP Response's header indicates so. This might be through setting the "Expires" header or the new "Cache-Control: max-age=number_of_seconds" header. This provides the period till when the cache is valid.
  2. The browser uses this cache (without sending a request to the server) when the Back button, or the Forward button is clicked, and when accessing the History or Bookmarked url, provided the cache has not expired.
  3. If the Refresh button is clicked, then the browser sends a request to the server since it is an explicit request by the user to reload the page. The HTTP Request header "If-Modified-Since" will have the time period which the server can check against. The server thus has an opportunity to send fresh contents. But if the cached contents are still valid, then the server need not send any body in the response but just send a 304 status in the HTTP Response. If a 304 status is seen by the browser, the browser's cache is reused. If an ETag was sent in the original HTTP Response (ETag: exampleETagValue) then the browser sends this value as "If-None-Match" conditional header in the HTTP Request along with the "If-Modified-Since". As explained before the server can validate the cache by checking whether the ETag is still valid or not.
  4. If the cache has expired (due to the expiration period being
    completed, or due to explicit cache clearance by the user), then the
    server must send a response containing the content. For such a request, the conditional HTTP Request headers will not be present.
I think this about covers the basics of expiration and validation caching in HTTP 1.1 used by the browsers. If you have any contradictory or supplementary information, please do let me know, as I'm new to this as well.

Comments:

i want to know if is code correct
<FilesMatch "\\.(ico|flv|jpe?g|png|gif|js|css|swf)$">
ExpiresActive On
ExpiresDefault "access plus 1 month"
</FilesMatch>

Posted by air force one on December 15, 2009 at 03:44 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

karthiksudarshan

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today