How to Enable Leverage Browsing Caching On Linux Server Running Apache

by Sandeep B.

Leverage browser caching Page load times can be significantly improved by asking visitors to save and reuse the files included in your website.

  • Reduces page load times for repeat visitors
  • Particularly effective on websites where users regularly re-visit the same areas of the website
  • Benefit-cost ratio: high
  • Access needed

Every time a browser loads a webpage it has to download all the web files to properly display the page. This includes all the HTML, CSS, JavaScript and images.

Some pages might only consist of a few files and be small in size – maybe a couple of kilobytes. For others however there may be a lot of files, and these may add up to be several megabytes large. Twitter.com for example is 3 MB+.

The issue is two fold.

  1. These large files take longer to load and can be especially painful if you’re on a slow internet connection (or a mobile device).
  2. Each file makes a separate request to the server. The more requests your server gets simultaneously the more work it needs to do, only further reducing your page speed.

Browser caching can help by storing some of these files locally in the user’s browser. Their first visit to your site will take the same time to load, however when that user revisits your website, refreshes the page, or even moves to a different page of your site, they already have some of the files they need locally.

This means the amount of data the user’s browser has to download is less, and fewer requests need to be made to your server. The result? Decreased page load times.

Why is it important?

The main reason why browser caching is important is because it reduces the load on your web server, which ultimately reduces the load time for your users.

How to Enable Leverage Browser Caching?

For Leverage Browsing cache to work You need to enable mod_expires module under apache you can check the apache documentation how to enable it.

I assume you already enabled mod_expires now to enable Leverage caching you need to put this lines under .htaccess of your site :

<filesMatch ".(ico|jpg|jpeg|png|gif|js|css|woff)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>

that’s it, you have enabled Leverage  browsing caching for your site this will work on CWP, Cpanel and any apache based server.

If this post helps you in any way please consider a donation

Donate with PayPal :

md-donate

You may also like

6 comments

David August 22, 2018 - 7:26 am

Hi, thank you for a great site and great tutorials. I personally use it for CentOS Web Panel.
One thing about this post – you assume we’ve already enabled mod_expires, but:
A. How can I check if it’s already enabled (just installed CWP yesterday and still new with it)?
B. How can I enable it if it’s not already?

TIA.

Reply
Sandy August 22, 2018 - 12:25 pm

Hello David here is the process
edit: /usr/local/apache/conf/httpd.conf
find this line
#LoadModule expires_module modules/mod_expires.so
and remove the “#” in-front of the line (un-comment)

then restart HTTPD:
service httpd restart

Reply
David August 22, 2018 - 1:06 pm

Thank you so much! By the way, would you know why file manager plugins in wordpress would return “Unable to connect to backend. HTTP error 400”?

Reply
David August 22, 2018 - 1:30 pm

Here’s a screenshot: https://pasteboard.co/HAkTSvr.png

Reply
David August 22, 2018 - 2:48 pm

Funny! After going over this guide, the file manager plugin now returns error 500…

David August 22, 2018 - 2:59 pm

Disregard. Problem fixed.

Leave a Comment