Knowledge Base Article

How to speed up your site by remote caching static content

Even though almost all sites are dynamic nowadays they still serve a lot of static content. Static content is content that is not generated on the fly and does not change often, i.e. all graphics, videos and most importantly site css and javascripts.

If your visitors come back often to your site it makes sense to instruct their browsers to keep the static content locally for a certain period of time and re-use it. For this purpose we can use Apache mod_expires. It can be enabled in a local .htaccess file where you can specify all of its rules too.

Here is an example:

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html "access plus 1 days"
ExpiresByType image/gif "access plus 1 weeks"
ExpiresByType image/jpeg "access plus 1 weeks"
ExpiresByType image/png "access plus 1 weeks"
ExpiresByType image/x-icon "access plus 1 years"
ExpiresByType text/css "access plus 1 weeks"
ExpiresByType text/javascript "access plus 1 weeks"
ExpiresByType application/x-javascript "access plus 1 weeks"
ExpiresByType application/x-shockwave-flash "access plus 1 weeks"
</IfModule>

The above rules give specific expiration periods for each content type such as text, images, css etc. The counter starts when the content is accessed once and then to it is added certain predefined period resulting in expiration date. Only after this expiration date the remote browser is supposed to re-download the content unless the user clears browser cache manually.

Caching static content at visitors' end with mod_expires can significantly speed up your site and decrease the server load. Static content is usually the largest and slowest to download. Enabling mod_expires can be very useful especially to forums, chats or other sites where same users revisit them often.



Rating

Please indicate if this article was helpful for you.

rating :  4.8 from 5
views :  766
votes :  4

Haven't found what you are looking for? Suggest an article HERE.

powered by

Valid XHTML 1.0 Strict Valid CSS!