Add Expires Headers WordPress on Apache or Nginx

How to Add Expires Headers To Your WordPress Website

4 minutes read

Tutorials

One perfect way to accelerate your WordPress is to Add Expires Headers WordPress in your .htaccess file setup.

The expires header informs the web user that the content of your website or another part can be used after some period of time has elapsed. With expires headers, you can set this amount of time. When you add header expires, the number of HTTP requests from the server will be considerably reduced, which will significantly reduce load times on your website.

In this article, you will get the chance to learn the easiest ways to Add Expires Headers WordPress.

What are Expires Headers?

Expires headers notify the browsers what resource the browser or the source can store and accumulate. It would also help you load the site more easily, by revealing those things in the cache and not needing to get them from the server.

Using the expires headers, you maximize the speed of your Site through reducing the HTTP requests between your device and the Service.

How to Add Expires Headers WordPress?

A flexible content management system is WordPress. This ensures that it is adaptive and provides many ways to solve a dilemma. This is why we’ll show you in this section how to manually add expires to servers like Apache server, Nginx, and CDN systems.

Overall, expires headers make the website quicker. You may add headers for particular files to expire, or use them for any file form. The expiry times can be modified according to your site content. For instance, you may want to set longer expirations if your website uses files that will stay unchanged for a long time. If the data shifts, you will set shorter dates of expiry.

Manually Add Expires Headers WordPress on Apache or Nginx

On Apache Webserver

Apache, the server language which configures the expires module, is one of the most common platforms to manage the cache.

You will first need to open your .htaccess file if you want to apply headers to expires or customize them on Apache. Although cPanel or FTP may be used for this, cPanel is easier to do. Here are the steps you need to follow:

  • Log into your account of cPanel
  • Now, open the File Manager icon

How to Add Expires Headers WordPress

  • Search for .htaaccess file
  • After that, right-click on the file and select edit

How to Add Expires Headers WordPress

Now, you just need to copy and paste the code given below:

<IfModule mod_expires.c>
ExpiresActive On
# Images
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"
# Video
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/mpeg "access plus 1 year"
# CSS, JavaScript
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
# Others
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
</IfModule>

Finally, save the file and save the changes.

The above code sets picture expiry dates to a year. Every month, CSS and JavaScript files are replaced and cache-deleted. It gives them a two-month expiry date when you submit the file. Expiration times can be accurate with counters such as years, months, weeks, days, hours, minutes, and seconds. This helps the cache to be specifically programmed.

On Nginx

The function of NGINX is distinct from that of Apache. This is why the .htaccess file can’t be found. The explanation is because of NGINX ‘s central performance philosophy. By removing the need for the .htaccess register, the server can access information quicker.

Only copy and add the code to the server block as seen below. This sets the expires in NGINX headers.

location ~* \.(jpg|jpeg|gif|png)$ {
expires 365d;
}

location ~* \.(pdf|css|html|js|swf)$ {
expires 2d;
}

Add Expires Headers WordPress using Plugin

Adding headers manually requires some technical skills. However, you can only use plugins if you are not technologically well prepared.

In this section, we show you the steps for adding Expires Headers WordPress with two popular plugins, Hummingbird and WP Rocket.

WP Fastest Cache

Add Expires Headers WordPress using Plugin

Instantly, without any trouble, with this plugin, you can apply expires headers to your .htaccess without the need to code. It’s very fast and effective to use.

Add Expires Headers

Add Expires Headers WordPress using Plugin

This plugin will help you add Expires Headers, but it also enhances the reliability of your site and allows cache work for you.

Hummingbird

Add Expires Headers WordPress using Plugin

Hummingbird is a free plugin to optimize the pace of your website. It also has good options for caching.

If you want to dramatically speed up the web site, expires headers are a perfect choice. The browser can view the cache files, which will speed up the loading of the web.

Congratulations, you have finally learned how to Add Expires Headers To Your WordPress Website. Moreover, some of the visitors also asked us about How to Delete Categories In WordPress. Do check the dedicated article on this.

We accept any type of suggestions from the visitors because it always motivates us to improve. Feel free to comment below.

 

 

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Related Articles

Menu