Search Engine Optimization & Performance tuning for your Joomla website

Leverage browser caching

Want to support this site? Buy my E-book: Joomla 3.5 SEO & Performance!

Browser caching helps to speed up your Joomla website by using resources cached in your browser (this is different then the "Use Browser Caching" setting in the System - Cache plugin!).

Basically what you do is you specify an expiry limit for certain file-types. As long as the expiry has not passed, the resources will not be downloaded again, but the downloaded version will be used. Of course the risk exists that resources that have been changed in the mean time will not be picked up, but for most sites this should not be a problem.

To further optimize your .htaccess file, you may need to add some more rules:

  • ETag: Inform browser that image has already downloaded and should not be reloaded
  • Expires headers: like ETag but more specific per file types
  • AddOutputFilterByType DEFLATE: minifies HTML by removing blanks

You specify these rules in your .htaccess file (it does not work if you still use htaccess.txt, so make sure to rename it). There are a lot of ways you can specify your rules, dependant on what file-types you use on your site, and how long the expiry should be. A simple example to start off with could be the following:

<IfModule mod_expires.c>
  FileETag MTime Size
  AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 600 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 216000 seconds"
  ExpiresByType application/xhtml+xml "access plus 600 seconds"
  ExpiresByType application/javascript "access plus 216000 seconds"
  ExpiresByType application/x-javascript "access plus 216000 seconds"
  ExpiresByType image/x-icon "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"

Note that your server needs to support the mod_expires feature in Apache. For safety, the if-statement is there, as if your host does not support it, your site will crash (or maybe your localhost installation). With the if-statement in place, the code will simply not execute.

You may need to further enhance the code and add rules for other file-types you use, like .mpeg, .woff, etc., or chance the expiry if it does not suit your needs.

For a more advanced example of a .htaccess file (including a lot of security rules), see the site.

Before you make any changes, first make a backup of your .htaccess file, and make sure to test thoroughly after activating the change. Check before and after to see if the change made a difference to the speed of your Joomla website.

Like this article?    Share it!