Databases Reference
In-Depth Information
ExpiresByType text/css "access plus 7 days"
FileETag None
The directives for the mod expires module are quite logical (and well documented); it is fairly easy to
understand what they mean even if you have never seen mod expires rules before. In this case, I first
enable the mod expires module with this line:
ExpiresActive On
Next, we define the rules for the different content types, based on their mime type. For example:
ExpiresByType image/gif "access plus 15 days"
means that all GIF images will have an expiry header added with a date to expire 15 days from the date
they were just accessed. In other words, if the browser needs that GIF image again and it is within 15
days from the time it was last requested from the web server, then the browser will be able to use the
cached local version. The rest of the rules follow a similar pattern. In the case of Javascript and CSS files,
we define shorter cache durations since we expect those files to be changed more frequently. The final
line
FileETag None
disables ETags. So what are ETags? Well, ETags (Entity Tags) are a way for the browser and web server to
determine if a resource has changed. So, for example, if the browser needs to load the logo for your web
page, it can contact the web server and ask if the resource is different to the cached version that the
browser already has. If the resource is different (in other words, if it has changed), the web server will
send the browser the updated version. If the resource has not changed, the web browser can use the
cached version, thereby saving the overhead of downloading the new version. The way the browser and
server determine whether the resource has changed or not is via the ETag, which is essentially a unique
identifier based on attributes of the resource (perhaps the last updated date, or the file size, or a
combination). You don't need to worry too much about how ETags work since the server is responsible
for generating the ETag identifiers transparently if you have them enabled.
So how do ETags compare to Expiry Headers, and would you benefit from them? Well, they certainly
can help in some situations and at first glance might appear to perform the same functionality as Expiry
Headers. However, there is a very subtle difference, namely:
When you use ETags, the browser still always contacts the web server to verify if
the resource has been modified.
When you use expiry headers (and no ETags), the browser will only contact the
web server if it does not have the resource in the local cache or the expiry date has
passed.
Whenever I present on this topic, I have a little example which I think helps to illustrate the subtleties, so
please bear with me while I describe it. If you think about the different options regarding expiry headers
and browser caching, it's a bit like making a cup of coffee (I told you,bear with me!):.
No caching : I get up in the morning, look in the fridge and find I have no milk so I
go to the store, buy some milk, and come back home and make my coffee. Every
time I want to make coffee I go back to the store to buy fresh milk.
Search WWH ::




Custom Search