Let’s try to make it easy to understand for anyone and everyone.
We need to understand a bit about how browsers help to improve user experience on a website.
All browser applications use a cache to store certain media or resources such as CSS files.
This caching action, decreases page loading time, translating into a delightful user experience.
An important thing to note is that these files are ones that are not changed frequently. A web browser will store these files in the cache. When the page is requested again, the files will be loaded through the browser cache instead of the webserver.
This is WHERE “Expire Headers” will help you make a faster loading web page.
Got it so far?
Let’s get into a bit more detail and discover HOW the magic happens.
It’s quite simple. All is you need to do, is to set the correct rules in a particular file stored on the webserver. These rules set the date to discard old copies and get fresh copies from the webserver.
HOW WILL BROWSER CACHE EFFECT LOAD SPEED OF A WEBSITE?
When a user clicks on a link in the browser, an HTTP request goes to the web server browser to allow file download. The browser then stores the files in the cache for a specified period.
The browser will serve the files immediately instead of requesting the webserver.
Let us take a look at an example that will help you understand how browser caching can be leveraged for better page speed.
GTMetrix is a specialized website performance analysis tool. The best digital marketing companies use it to track website metrics. A typical report from a website analysis performed on GTMetrix would look like this
On the screenshot you see, the third recommendation is “Leverage browser caching”. Digital marketing experts know that this requires the addition of “Expire Headers”.
HOW TO ADD EXPIRE HEADERS?
There are two ways in which Expires Headers can be added to leverage a browser’s caching ability.
We can choose to add Expires Headers manually or by using an appropriate plugin. Let’s find out how to do this using both methods.
1. ADDING EXPIRES HEADERS IN WORDPRESS MANUALLY
The solution presented here will show you how to add Expire Headers on Apache and NGINX servers in 4 easy steps.
STEP 1 – Log in to C-Panel on your hosting account.
STEP 2 – Locate the File Manager icon as highlighted below. Click on it.
After clicking on the File Manager icon you should be in the files and folder structure of your website.
STEP 3 – Now locate the folder “public_html” (highlighted by the red box & arrow) with a blue globe icon on its side. Go ahead and click on that.
STEP 4 – The public_html folder stores the “.htaccess” file. Navigate your pointer to the “.htaccess” file and RIGHT CLICK on it. When you are presented with a menu, choose EDIT.
Now comes the easiest part.
Just copy and paste the lines of code displayed below.
ExpiresByType image/jpeg “access plus 1 year”
ExpiresByType image/gif “access plus 1 year”
ExpiresByType image/png “access plus 1 year”
ExpiresByType image/webp “access plus 1 year”
ExpiresByType image/svg+xml “access plus 1 year”
ExpiresByType image/x-icon “access plus 1 year”
ExpiresByType video/mp4 “access plus 1 year”
ExpiresByType video/mpeg “access plus 1 year”
ExpiresByType text/css “access plus 1 month”
ExpiresByType application/pdf “access plus 1 month”
ExpiresByType application/x-shockwave-flash “access plus 1 month”
2. ADDING EXPIRE HEADERS IN WORDPRESS BY USING PLUGIN
If you are not comfortable with editing any files then Adding Expire Headers from .htaccess is not be advisable. Any type of mistake in editing can render the website inaccessible.
Luckily plugins are available for WordPress users to solve this issue. Some of the highly recommended plugins are:
ADD EXPIRE HEADERS PLUGIN
Reduce page load time by caching browser
Improve user experience
Decrease the total data size of the page
It has both free and pro features.
W3 TOTAL CACHE
WP Rocket is also a great plugin. That is if would like to go with a premium and can afford it.
Starting at 49$ per year it offers a lot. From caching and gzip to compression, lazy loading expires headers and a whole lot more. You don’t need to access any files or add, delete or edit a single line of code. This plugin will do everything for you and keep your website in tip-top shape.
Bookmark this page and come back to it if you need a refresher.