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:
1
2
3
4
5
6
7
8
9
10
11
12
|
<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.
You find this article useful? Click here to learn more about Hostlantern web hosting experts and what else we can do for you!