HTML and CSS Reference
In-Depth Information
Enable Caching
Apply cache control headers so that dynamically generated pages can also be cached when appropriate.
HTTP/1.1 200 OK
Date: Sun, 08 Apr 2007 20:58:58 GMT
Server: Apache/2
X-Powered-By: PHP/5.2.0
Content-Length: 325
Content-Type: text/html; charset=UTF-8
HTTP/1.1 200 OK
Date: Sun, 08 Apr 2007 20:58:58 GMT
Server: Apache/2
X-Powered-By: PHP/5.2.0
Cache-control: public
Last-Modified: Fri, 03 Dec 2004 11:53:03 GMT
ETag: "6548d4-30a9e-c7f4e5c0"
Content-Length: 325
Content-Type: text/html; charset=UTF-8
Motivation
Caching is a crucial part of web performance and scalability. Caching can take place at many levels: on the
server with gateway proxies, between the client and the server in proxy servers, and in the browser itself
through local history. The fewer connections the client makes and the more it can act on information it already
has, the faster both the client and server can run.
Web servers' default configurations are fairly good at managing caches for static files, and you don't need to
worry a lot about that. However, web applications that manage their own HTTP headers require more thought
and care. Most especially, web applications accessed via POST and ones that make use of URL query strings
must be especially considerate of cache control headers because much software does not cache the result of
GET requests that use query strings or any POST request. However, by manipulating the HTTP header you can
indicate to the client that it is acceptable to cache some of these.
Potential Trade-offs
Not everything should be cached. You do want to be careful before blindly allowing caching. Done wrong,
caching can deliver stale information or expose users' private data.
Cacheable pages will measure fewer hits than unncacheable pages. If that's a major problem for you, the next
section explains how to prevent caching, rather than enabling more of it. However, most sites benefit heavily
enough from caching that they'd like more of it, not less.
You can also use the techniques in this section to enable caching of some resources but not others. For
example, you might allow the main HTML pages to be cached but disallow caching of ads. That would enable
more precise measurement of just how many people are seeing your ads.
Mechanics
Search WWH ::




Custom Search