If you visit again a day later, the files will be uploaded quickly from the browser, and you can reduce resource usage and save time. Also, the speed of viewing the page on the website will increase. But the problem is that the browser cache does not hold files forever. After a certain time, the files will replace with fresh copies. This point is where the expired headers come in. They contain a specific date to discard cached files and also fetch new ones. In this post, we are going to talk about how to add expires headers. Let’s get started!
Examples of Expires Headers
ExpiresDefault “access plus…:
- “2881700 seconds”
- “access plus 1 month”
- “access plus 2 years”
- text/html “access plus 8200 seconds”
- text/CSS “access plus 1 year 1 month 5 weeks”
- text/jpeg “access plus 1 year 1 month 5 weeks 10 days”
As you can see, you can set the time based on hours, days, or even years.
How to Add Expires Headers to .htaccess
To add expires headers to your website, you need to edit the .htaccess file. You can download the .htaccess file and then add the code below.
## EXPIRES CACHING ##
Type ExpiresByType image/, then type:
gif “access plus x year”
- png “access plus x year”
- webp “access plus x year”
- svg+xml “access plus x year”
- x-icon “access plus x year”
ExpiresByType video/mp4 “access plus x year
ExpiresByType video/mpeg “access plus x year”
ExpiresByType application/x-shockwave-flash “access plus x month”
## EXPIRES CACHING ##
Don’t forget: After making the changes in the .htaccess file, you have to save the changes and then upload them back to your site’s root.
How to Add Expires Headers to WordPress: Using a Plugin
Adding lines to your .htaccess file may lead to problems, especially if you do not have enough experience. Besides, you may not have access to the .htaccess file. To overcome these problems, one of the most efficient ways is to use plugins in WordPress.
Here are the steps to add expires headers to WordPress:
- Open your WordPress dashboard
- Go to the Plugins section
- Click on the Add New option
- Click on Install now and then Active
- Open the Settings section
- Go to the AddExpiresHeaders section
- Select the Types and Expiry Times
- Click on the Save button
FAQ About Adding Expires Headers
As we mentioned above, there are a lot of file types that you can prefer. Let’s give some examples.
There are two significant benefits that you cannot ignore. The first one is that expires headers help you reduce server load and then reduce resource usage. The second one is that they allow you to increase page load time. Therefore, you will be able to save your time.
WordPress plugins are small software applications that allow you to add new features to your WordPress website. They integrate with your site. At the end of the day, you can create almost any type of website with WordPress.
There are hundreds of paid or free caching plugins that you can choose from. Here are some of these paid and free, or both, caching plugins.
WP Rocket – Includes Browser Caching (paid)
Super Cache (free)
Fastest Cache (free and paid)
W3 Total Cache (free and paid)
Swift Performance (free and paid)
Cache Enabler (free)
WP Super Cache (free)
Hyper Cache (free)
Leverage Browser Caching (free)
High website access speed is essential to have a high rank on Google or other search engines. Therefore, efficient expires header features help you improve great user experiences. That’s why they play a great role in your SEO strategy.
Adding Expires Headers in Short
Using expires headers is a perfect method to increase your site’s load speed. This post showed you how to add expires headers to your web server by using the .htaccess file and WordPress Plugins. We hope you found this post helpful. If you feel like you need to take a few steps back start with our guide on HTML.