Although today most of the websites are dynamic, they still contain a lot of static content. Static content is the content that is not generated on the fly and no changes are made to it. This includes content like graphics, videos, website CSS and Java scripts.
If your visitors frequently come back to your website, then you must take the necessary steps to instruct their browsers to store the static content locally for a certain span of time and re-use this content. For doing this, you can use Apache ‘mod_expires’ function. This function can be enabled in a local .htaccess file where you can specify all the rules as well.
Here is an example:
1 <IfModule mod_expires.c>
2 ExpiresActive On
3 ExpiresByType text/html “access plus 1 days”
4 ExpiresByType image/gif “access plus 1 weeks”
5 ExpiresByType image/jpeg “access plus 1 weeks”
6 ExpiresByType image/png “access plus 1 weeks”
7 ExpiresByType image/x-icon “access plus 1 years”
8 ExpiresByType text/css “access plus 1 weeks”
11 ExpiresByType application/x-shockwave-flash “access plus 1 weeks”
The rules mentioned above assign specific expiration periods for every type of content like text, images, css etc. The counter gets started when the content is accessed for the first time and then a certain pre-defined period is added to it resulting in an expiration date. After this expiration date, the remote browser has the task of re-downloading the content unless the browser cache is manually cleared by the user.
Also read: Website Slow/Down – FAQ
By caching the static content at the visitor’s end with the ‘mod_expires’ Apache function can speed up your website speed significantly and it decreases the server load as well. Static content is generally the largest and slowest to download. Enabling ‘mod_expires’ can be extremely useful, especially for the websites that contain forums, chats or other such websites where users keep re-visiting.