Expires headers are HTTP headers informing you how soon the cached copies of website resources will expire. So before the expiry date, the browser can grab the site from the cache. Once the resources are passed, they won’t be available in the browser and can later be requested from the server.
The HTTP status will ensure that the user won’t land on the outdated content page and speed up the loading time. However, before we get into this well, first look at the browsing cache so it will be easier for you to understand expires headers.
When you visit a website, the browser communicates with the website server to request and download the files required to display the webpage. Depending on how complicated a page is, tons of files are transferred between the browser and the server.
The fantastic thing about this is that if expires header is set for the requested files. Then, the next time you visit the same website, the browser will be able to show the files that are quickly available from the cache instead of requesting again to the web server. This is because, most of the time, web pages are already available. So the browser does not need to ask the server.
Benefits of Expires Headers
Adding expires headers will give you some of the benefits:
- First, it reduces the number of HTTP requests sent by the browser to the server.
- It also reduces the number of files that need to be downloaded.
- With the above benefits, you will have another advantage: it will reduce the website’s loading time.
How to Add Expires Headers in WordPress?
You need to modify your server files or use a plugin to add expires headers in WordPress. You should use the Plugin if you don’t have any technical experience.
Modifications are meant for those who are experts in this because if something goes wrong, the server files can break something from your website. Better hire someone or use a plugin.
Add an Expires Header with the Plugin:
You can use a WordPress plugin to enable expired headers on your website. Many options are available online, but you can use the Cache Plugins. This is an excellent option among different others. How? This Plugin will enable browser cache and expires headers in fewer clicks.
Let us see the steps on how we can do it:
- Click Performance > Browser Cache
- Scroll down to the General Sub box
- Check off the option Set Expires Header.
Once you have done the above steps, you need to scroll down to the CSS and JS section, check the box beside the expires headers and enter the time in Seconds. It would help if you converted the time you want for the availability of the expires header into seconds. For example, for 365 days, the seconds are 31536000.
Lastly, click on the save settings.
Add Expires Headers without Plugin:
This manual process of adding the headers in WordPress depends on your server. Below we have used an Apache server example to explain to you:
- The first step is to connect to your server through the hosting panel or with an FTP client.
- Next, navigate to public_HTML.
- Look for the .httpacess file. For this step, you need to select the show hidden files.
- You can pen the file in the hosting panel file editor or download it and then view it in the code editor. Then add the code snippet that you can find online on the internet. Different files have different expiry dates. You can change the date depending on your content.
- Lastly, save the file.
Format of Expires Headers
The expires headers have two formats:
ExpiredDefault: You can use this format to put the expiration time to all types of files by default. The syntax of this header is ExpiresDefault access. (Time Interval).
ExpiresByType: You can use this format to put the expiration time to different types of files. File name and Time Interval.