Forum Moderators: open
I am trying to optimize my page (xmas clean up so to speak) for best performance. I am not using any "cache" tags/commands or whatever in my HTML source code right now, nor any special apache mod_expire directives.
I have been wondering ever since if people are always speaking about one and the same cache or if there are several caches? Is it only the browser cache and sometimes the proxy cache that is meant, or do I need to be concerned about different caches and make sure that I have different settings and directives in place?
I am not speaking about any server side caches - I know what my server is doing. I am more concerned what is being cached on the browser and in proxy’s. In fact I would like to speed up the visitors browsing experience, and as a side effect save a bit of traffic.
Before playing around with mod_expire and stuff and adding cache related meta tags to my source, I just wanted to make sure I know what I am doing.
Thanks for any comments.
There are any number of caches between you and the user's client browser. However, you really only need to be concerned with what are termed "proxy" and "private" caches. The "private" cache refers to the user-agent (usually the browser) cache, i.e. "Temporary Internet Files", and the "proxy cache" refers to any caching proxies, corporate caches, or whatnot in the public network between you and the client.
Because only browsers read html, it is better to do the cache-control at the server, using mod_expires and mod_headers, or by using the header-generation capabilities of scripting languages such as Perl and PHP. Since you didn't mention mod_headers, just be aware that you can do stuff like this with Apache mod_expires and mod_headers:
# Set up Cache Control headers
ExpiresActive On
# Default - Set http header to expire everything 2 weeks from last access, set must-revalidate
ExpiresDefault A604800
Header append Cache-Control: "must-revalidate"
# Apply a customized Cache-Control header to frequently-updated files
<FilesMatch "^(test2?¦404¦410¦403i?)\.html$">
ExpiresDefault A1
Header unset Cache-Control:
# (commented out) Header append Cache-Control: "no-store"
Header append Cache-Control: "no-cache, must-revalidate"
</FilesMatch>
<FilesMatch "^(calendar¦actvty_sched)\.html$">
ExpiresDefault A14400
</FilesMatch>
<FilesMatch "^index\.htm">
ExpiresDefault A7200
</FilesMatch>
<FilesMatch "^robots">
ExpiresDefault A3600
</FilesMatch>
You can use mod_expires to take care of expires and max-age, and use mod_headers to "manually" configure
the following:
Cache-Control: no-store
This object may not be stored in any cache, even the requestor's browser cache.
Cache-Control: no-cache
This object may be held in any cache but it must be revalidated every time it is requested.
Cache-Control: private
This object can be stored in the requesting browser´s cache but not in a shared cache ...
Cache-Control: must-revalidate
Tells caches that they must obey any freshness information you give them about an object. The HTTP allows caches to take liberties with the freshness of objects; by specifying this header, you're telling the cache that you want it to strictly follow your rules.
Cache-Control: proxy-revalidate
Similar to must-revalidate, except that it only applies to proxy caches.
Refs:
http://www.mnot.net/cache_docs/
http://webmaster.info.aol.com/caching.html
Jim