Leverage Browser Caching Joomla [How to Enable it Quickly]

One of the easiest ways to make your Joomla website faster - which involves no effort at all from your side, is to leverage Joomla browser caching. This is one of the high priority tasks recommended by Google to make your website load faster.

Contents[Show]

Essentially, what you are doing is reusing any files which exist on the users' machine, without having to download them again. By extending the caching lifetime (or how long a file takes to become old), you are making sure that your visitors do not spend time downloading the same files every time they visit your website.

This change involves very little changes and is not very complicated and this web design blog will tell you exactly how to do it.

If you're looking for a way to leverage browser caching for WordPress - we've written about that too here: https://www.collectiveray.com/leverage-browser-caching-wordpress.

Not that there are two primary ways:

  • Using the Page Cache plugin
  • Manually by changing the .htaccess file

Let's have a look at both of these options:

Enable browser caching via System - Page Cache Plugin

The simplest way to enable browser caching in Joomla is to use the built-in support, using the System - Page Cache plugin. To enable browser caching using the plugin:

  • Go to Extensions > Plugins
  • Search for Cache
  • Click on the System - Page Cache plugin
  • Switch on the Use Browser Caching switch 
  • Change the status of the plugin from disabled to Enabled
  • Click Save.

enable browser cache joomla system plugin

Notes on using this function. The Joomla documentation does not state how long the files will be cached for. We would assume that the time would be around 1 month.

Also, if you have pages that require session-based information, such as a shopping cart, make sure that you exclude these pages. You could exclude the whole menu items as per the above, or switch to the Advanced tab to exclude specific URLs, or URL regular expressions.

Change .htaccess to increase Joomla browser cache

To set the expiry time of files such as images and CSS files, this requires a slight modification to your .htaccess file, which is found in the root of your hosting server. This is done by changing the expire headers.

Add Expires Headers to Joomla

As a bare minimum, you add the following in your .htaccess file. To do this, simply access your hosting CPanel, and with your File Editor, find the .htaccess file and add the following to the bottom of the file.

Do not make any other changes.

<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 application/xhtml+xml "access plus 600 seconds"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType text/javascript "access plus 1 month "
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType application/x-javascript "access plus 1 month"
  ExpiresByType image/x-icon "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
</IfModule>

We are setting files that refresh quickly such as the HTML of your site to expire after 600 seconds, whilst we are changing such things as the CSS and Javascript to only expire one a month. This means, that if your visitor visits the site again within a month, they don't need to redownload your CSS and JS files again. If you know that you rarely perform these types of changes on your site - you can see the value higher, to 1 year, similar to the jpeg, png expires header

Set Image files change to a long browser caching expiry

As you can also see in our example above, our image files are set to expire only once a year.

This makes sure that the files which take the most time to download are kept on the visitors' machine, and won't have to be downloaded again next year. Due to this change in your Joomla browser caching - the images are not downloaded again for one whole year.

This makes the experience of a returning customer much more positive. You can choose to make this time, longer or shorter depending on your own website's requirements.

Frequently Asked Questions

What is leverage browser caching?

Leverage browser caching means you should take advantage (leverage) of the functionality of the browser caching function. By default, browsers support caching of files until they "expire" i.e. they are deemed as stale and require a refresh. The webserver can instruct the browser how long before file files expire (for example, 1 month). By doing this, the browser can reuse the files without having to download them again, making your website load faster in the process.

How do I enable browser caching in Joomla?

You can enable browser caching in Joomla by enabling the System - Page Cache plugin with the Use Browser Caching option switched on. Or you could tweak the .htaccess file of your website as per the above.

Do I need to enable both options?

No, one of the above options is enough. With the .htaccess file, you have more granular control because you can choose the caching time yourself, and you can choose which file types to cache. You can also choose to cache some file types longer than others as per the needs of your website.

Wrapping Up

Still got a question about how to leverage browser caching in Joomla? Do drop us a line in the comments below. 

About the Author
David Attard
David has been working in or around the online / digital industry for the last 18 years. He has vast experience in the software and web design industries using WordPress, Joomla and niches surrounding them. As a digital consultant, his focus is on helping businesses get a competitive advantage using a combination of their website and digital platforms available today.

One more thing... Did you know that people who share useful stuff like this post look AWESOME too? ;-)
Please leave a useful comment with your thoughts, then share this on your Facebook group(s) who would find this useful and let's reap the benefits together. Thank you for sharing and being nice!

Disclosure: This page may contain links to external sites for products which we love and wholeheartedly recommend. If you buy products we suggest, we may earn a referral fee. Such fees do not influence our recommendations and we do not accept payments for positive reviews.

 

who are we?

CollectiveRay is run by David Attard - working in and around the web design niche for more than 12 years, we provide actionable tips for people who work with and on websites. We also run DronesBuy.net - a website for drone hobbyists.

David attard

 

 

Author(s) Featured On:  Inc Magazine Logo   Sitepoint logo   CSS Tricks logo    webdesignerdepot logo   WPMU DEV logo   and many more ...