.htaccess, use cache of browser to speed up site

July 4, 2016 21 Alex

Speed up work of site using client-side caching

To enable caching in the browser, add the following code in .htaccess:

<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|pdf|woff|css|js)$">
    Header set Cache-Control "max-age=604800"
</FilesMatch>

In which you must list all the file extensions (gif|jpg|jpeg|png|...), to be cached.

max-age=604800 - time that you want to cache files. Is given in seconds (in this case 7 days).

Possible mistakes

If you add this block in the .htaccess file and you got an error 500 Internal server error:

Most likely you do not have a module headers.load, for that would enable it you need to enter in sictemu as an administrator and run the following commands:

cd /etc/apache2/mods-enabled/
ln -s ../mods-available/headers.load headers.load
sh /etc/init.d/apache2 reload

Create a symbolic link to the mods-available/headers.load in mods-enabled and restart Apache.