It is already known that the loading speed of the web is one of the parameters of positioning and consequently to take into account for SEO. Therefore activating the browser cache is very important part of SEO to improve the experience of recurring visitors.
The apache servers usually bring the mod_expires installed and active, so that nothing will have to be touched in this regard. Just indicate the expiration directives in the .htaccess file as follows:
<ifmodule mod_expires.c> ExpiresActive On ExpiresDefault A3600 <filesmatch ".(jpg|JPG|gif|GIF|png|css|ico|js)$"> ExpiresDefault "access plus 7 day" </filesmatch> </ifmodule>
Or you can complicate a bit more by specifying different expiration for each group of files:
<ifmodule mod_expires.c> ExpiresActive On ExpiresDefault A3600 <FilesMatch ".(gif|jpg|jpeg|png|swf)$"> # 2 weeks ExpiresDefault A604800 Header append Cache-Control "public" </FilesMatch> <FilesMatch ".(xml|txt|html)$"> # 2 hours ExpiresDefault A604800 Header append Cache-Control "public" </FilesMatch> <FilesMatch ".(js|css)$"> # 3 days ExpiresDefault A604800 Header append Cache-Control "public" </FilesMatch> </ifmodule>
In case we do not have the mod_expires configured in our apache, it will not give us any errors, although we will not be able to specify a caching date.
In the ExpiresDefault directive We have added several types of time:
– ExpiresDefault A3600 one hour
– ExpiresDefault A604800 for a week
For those who use the firebug and the Google pagespeed module, they will be able to verify that the option “Leverage browser caching” appears with a green tick, this means that the result is positive and the indicated recommendations have been followed. Many of our elements have been cached at the browser level.
This tip works perfect with wordpress, just add the code lines to your actual .htaccess and check the change in Google PageSpeed Insights.