How to Add Expires Headers To Your WordPress Website 

1 What Are Expires Headers?

To understand expires headers and how to use them in WordPress, you must first understand the browser cache. HTML, JavaScript, and CSS are examples of static files that make up a web page. Because these files do not change regularly, the identical files will be retrieved both times if you request the page yesterday and request it again today.

What if you saved those files on your browser when you requested them yesterday? When you make today’s requests, those files will be swiftly loaded from your browser rather than from the web server, decreasing resource use and increasing page loading times.

That would be significantly faster, and caching accomplishes this.

On the other hand, the browser cache can’t keep a website’s files (images, CSS, Javascript, and so on) indefinitely; it needs to be instructed when to delete old ones and request new ones.

This is where the expires header comes in. They are rules specified in a website’s header section that advise the browser to discard cached files and fetch new copies.

You can use a plugin or edit your server files to add expires headers to WordPress. The former is best for advanced users since making a mistake when modifying your server files can break something on your site. A plugin is better if you don’t have a lot of technical knowledge.

2 How to Add Expires Headers to Your WordPress Website?

2.1 Using A WordPress Plugin

To enable expires headers on your site, you can use the WordPress plugin. While there are many plugins to choose from, caching plugins is an excellent choice. This plugin enables browser caching and expires headers in just a few clicks. Let’s have a look at the steps with W3 Total Cache.

At first, install and activate the plugin from Plugins > Add New section of your WordPress dashboard.

Install and activate W3 Total Cache plugin to add expires headers

Once you’ve activated the plugin, navigate to Performance > Browser Cache. In the Generalsub-box, Check the option Set expires headers as shown below.

Enable expires headers

Now go to the CSS & JS section and select the box next to the Set expires header, then input your Expires header lifespan value in seconds. By default, this number is set to 31536000 seconds or 365 days. This can be changed as needed.

CSS & JS section

Repeat the above step for the HTML & XML and Media & Other Files sections. Once done, click on Save all settings button.

2.2 Add Expires Headers On An Apache Server

If your site host utilizes the Apache web server, you can use the .htaccess file in the root folder of your server to add expires headers. 

Rank Math makes it extremely easy for you to edit your .htacess file right inside your WordPress dashboard. You can edit your .htaccess file by navigating to Rank Math > General Settings > Edit .htaccess.

Edit .htaccess with Rank Math

You can also edit the .htaccess file by connecting your server through your hosting panel with the help of an FTP or cPanel. For simplicity, we will use the cPanel to establish the connection. 

First, you need to log in to your cPanel. Once the connection is established, navigate to File Manager and click on the public_html folder. 

navigate to public_html folder

Once you’ve entered the folder, look for the .htaccess file. If you still can’t find it, make sure the hidden files option is set to show.

For Full Details Go here >>

Open .htaccess file

Add a Comment

Your email address will not be published.