- Site Check – Web Site Advice - https://www.sitecheck.be -

Cache Control

Using Cache Control to reduce the number of request to your web server

When you run your log analysis tool, you’ll probably see a lot of requests with an HTTP code 304 (not modified). These requests are coming from browsers which check that the data in their cache is still current.

If you rarely modify your stylesheets, your javascripts and your images, then it might be a good idea to use cache control to let the browsers know on their first request that your data can be stored for a certain number of days before the local cache needs to be refreshed.

Check here if your server uses cache control [1]. If it shows that there are unnecessary server connections, then it’s about time you enable cache control on your site.

It be enabled in your .htaccess file (if you’re running Apache as your web server) or in the web server configuration (httpd.conf, virtual host configuration).

Here is a little screenshot from the statistics [2] of one of my sites (4 months of stats):

status.png

Notice the number of 304 requests. Many of these connections can be avoided when using Cache Control. I only recently started using Cache Control in order to reduce the load on my servers.

Put the following code into your configuration and the web browser will tell supporting browsers to store images, stylesheets and javascripts for 7 days in the local cache. This reduces the number of connections to your web server required and gives your visitors a better user experience as fewer connections are needed:

ExpiresActive On
ExpiresByType image/gif "access plus 7 days"
ExpiresByType image/jpg "access plus 7 days"
ExpiresByType image/png "access plus 7 days"
ExpiresByType image/vnd.microsoft.icon "access plus 7 days"
ExpiresByType text/css "access plus 7 days"
ExpiresByType text/javascript "access plus 7 days"
ExpiresByType application/x-javascript "access plus 7 days"

This is especially useful if you’re re-using the same scripts, stylesheets and images over and over again throughout your site. Browsers can just skip verifying those files on each subsequent page they load.