Understanding the browser cache
The browser cache can be customized by the server side by using the Last-Modified, CacheControl (or Expires with http 1.0) and ETag http headers.
Details about how these headers work can be found here.
CacheControl
CacheControl is the class that handles all the internals related to caching:
- Contains the desired caching strategy
- When a new request is received, it decides to send new contents or instead use a 304 (NOT MODIFIED) response.
- When sending a response, it sets the correct HTTP headers to indicate the caching policy to the browser.
Almost all Resolution classes support the CacheControl attribute:
When using the lastModified attribute keep in mind that the last modification date will be strictly compared (==) instead of using 'less or equals' (<=).
Weak and strong indicators
When caching, you may use a weak indicator like lastModified, a strong indicator like etag, or a combination of the two. If the etag includes information about the last modification timestamp, you can skip the Last-Modified header.
You can use the MD5 hash of your response (if known in advance, for example with binary files) as a GET parameter and mark the resource to get cached forever. This should be done only if the resource will not be modified frequently, otherwise the browser cache will easily get populated with garbage.
‹ Internationalization
up
Javascript - CSS resource bundles ›