Skip to main content

How to Leverage Browser Caching in WordPress – To improve page speed

verview
Leverage Browser caching is an important parameter that google and y-slow used to analyze the performance of your webpage. If you’ve ever run Google PageSpeed test on your website, it has recommended that you leverage browser caching.
Increase page load speed by leverage browser caching
What is Browser Caching?
When a user visit your webpage for the first time, their browser will store the copies of static files(images, java script, css, favicon, etc) of your webpage locally in their computer. This means the browser doesn’t have to download them again in-case the user re-visit your webpage, because browser will fetch data from the cache instead of asking the server. The end result is your webpage will appear to load faster in user’s browser. This process is called browser caching.
How does browser caching work
Why leverage browser caching?
Caching your website resources on the visitor’s computer will let them load your pages faster every time they come back to your site. If the resources are static, it is suitable for the contents that never or rarely need to be updated. This includes jpg, gif, png, favicon, javascript, css, etc. 
Google recommends that the static resources are cached at least once in a month. This is done bysetting the maximum age or expiry date for the resource in the HTTP headers.
Setting an expiry date or maximum age in the HTTP headers for static resources (images, js, css, etc) instructs the browser to load previously downloaded resources from local disk rather than over the network.  (source –Google)
This means, a first time visitor to your page will make several HTTP requests to cache several static resources. But the cacheable resources have short freshness lifetime. By adding expires headers, you can tell your website visitor’s browser to keep the resources for a certain period of time until the expiry date or maximum age is reached. This avoids unnecessary HTTP requests on subsequent page views.
Benefits of leverage browser caching:
  • Minimize the number of HTTP requests; which in turn reduce the load time of your site dramatically.
  • Save your visitor’s load time and data if they visit your site more than once.
  • Reduces the load on your web server and save bandwidth.
How to leverage browser caching?
1)  Tweak your .htaccess in the root folder of your WordPress
The .htaccess file will need to be in the root of your domain, typically the public_html folder. This file is a hidden file but should show up in FTP clients like FileZilla or File manager, here is how you do it.  
Note: Make sure you have a copy of your current .htaccess file before tweaking it.
On the server
  • Login to your cPanel account.
  • Click the File Manager icon, located in the Files section.
  • When the popup box appears, select Web Root (public_html). [Make sure that the Show hidden files option is checked]
  • Right click on the .htaccess and click on “Code Edit”.
  • Add the following code to the very top of your .htaccess file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##
This code tells your visitor’s browser that the static resources like images, javascript, flash, pdf, and icons should be cached for specified period of time, for example a month. You can change the duration based on your requirement. Set minimum age for frequently updated files and a maximum one for those that are likely to remain unchanged. One year is the maximum time you can set without violating RFC guidelines.
2)  Using a WordPress plugin
If you are not comfortable with editing .htaccess file, plugin might be an easiest way for non-techies to leverage browser caching within your WordPress admin panel.
Editing the .htaccess file through Wordpress SEO by Yoast
If you’ve WordPress SEO yoast plugin installed on your site, editing your .htaccess file is just a matter of a few seconds. It allows you to easily edit your .htaccess file directly from your WordPress admin, which is very handy.
  • Hover over SEO on the left side of your WordPress dashboard, then click Tools > File Editor.
  • Scroll down to .htaccess file section and paste the above code into the box.
Leverage Browser Caching with W3 Total Cache
Step 1:
If you’ve already installed W3 Total Cache simply head over to WordPress Dashboard » Performance » General Settings and Enable Browser cache
Enable browser cache in w3 total cache
Step 2:
Go to performance >> Browser Cache. Apply the following settings.
Browser Cache – General Settings
  • Enable “Set Last-Modified header”
  • Enable “Set expires header”
  • Enable “Set cache control header”
  • Disable “Set entity tag (eTag)”
  • Enable “Set W3 Total Cache header”
  • Enable HTTP (gzip) compression”
  • Disable “Prevent caching of objects after settings change”
  • Disable “Do not process 404 errors for static objects
Browser Cache – CSS & JS
  • Enable “Set Last-Modified header”
  • Enable “Set expires header”
  • Expires header lifetime – 31536000 seconds (1 year)
  • Enable “Set cache control header”
  • Cache Control Policy: cache with max-age
  • Disable “Set entity tag (eTag)”
  • Enable “Set W3 Total Cache header”
  • Enable “HTTP (gzip) compression”
  • Disable Prevent caching of objects after settings change “
  • Disable Disable cookies for static files “
Browser Cache – HTML and XML
  • Enable “Set Last-Modified header”
  • Enable “Set expires header”
  • Expires header lifetime – 3600 seconds (1 hour)
  • Enable “Set cache control header”
  • Cache Control Policy: cache with max-age
  • Disable “Set entity tag (eTag)”
  • Enable “Set W3 Total Cache header”
  • Enable “HTTP (gzip) compression”
Browser Cache – Media and other files
  • Enable “Set Last-Modified header”
  • Enable “Set expires header”
  • Expires header lifetime – 31536000 seconds (1 year)
  • Enable “Set cache control header”
  • Cache Control Policy – cache with max-age
  • Disable “Set the entity tag (eTag)”
  • Enable “Set W3 Total Cache header”
  • Enable “HTTP (gzip) compression”
  • Disable “Prevent caching of objects after settings change” 
  • Disable “Disable cookies for static files” 


Comments

Popular posts from this blog

October CMS E-Commerce Tutorial: GoT White Walkers Protection Store

As many of you probably know, Game of Thrones Season 6 is starting next April 24th. Now I recently introduced myself on this blog , but forgot to mention that I'm, like millions of others, a shameless GoT fan . When our content guy asked me to craft a post showing how the easy e-commerce integration we brag about would work with October CMS, I immediately picked GoT as a theme for the demo. ​ So in this post, I'm going to show you how to set up a store selling defense against the imminent White Walkers invasion. Because WINTER IS COMING big time, you know. ​ ​ More specifically, I'll provide a step-by-step e-commerce tutorial explaining how to integrate our shopping cart platform to an October CMS site. Let's get into it. ​ What is October CMS ​ We've been hearing about October CMS from developers here and there for a while now. This free, open-source CMS platform is the brainchild of fellow Canadian Alexey Bobkov and Australian Samuel Georges. It...

Creating a Custom Page in OpenCart

Creating a Custom Page in OpenCart by MarketInSG » Tue Apr 17, 2012 6:59 am I noticed a lot of users are searching for help on this topic, so here's a short tutorial for all of you. What you need: - Basic PHP knowledge - Basic HTML knowledge - Text Editor Required files to create a custom page: - Controller file - Template file Optional files: - Model file - Language file (I will be using it in this example here) Controller file Create a file name 'static.php' in /catalog/controller/information/ code inside the file (php) <?php class ControllerInformationStatic extends Controller {    private $error = array();            public function index() {       $this->language->load('information/static'); //Optional. This calls for your language file        $this->document->setTitle($this->language->get('heading_title')); //Optional. Set the title of your web page.   ...

Paypal In Pakistan Payoneer-Verified

Since there are a huge number of online organizations which just acknowledge Paypal as installment passage. Thusly I am going to demonstrate to you how you can make Paypal record in Pakistan and in what manner would you be able to check it ! It is an unlawful trap however you can utilize it for crisis purposes. Instructions to make and confirm Paypal record in Pakistan  Simply take after the regulated guide underneath to get your Verified Paypal Account. You will additionally get Virtual Bank Account in USA and  1 Master  Debit Card free of charge You will have the capacity to utilize that check card to cashout your trusts through Paypal from any ATM Machine. Go to  Paypal,  Sign up and Choose your nation as United States of America. Use  Fake USA Address,  But other all data ought to be 100% right. When you information exchange, confirm your email and login to your Paypal record. Presently you have your Paypal record, now is the rig...