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