How to Add Expires Headers

How to Add Expires Headers

Before learning how to add expires headers, you have to know what browser cache is. Every website has its own static files, such as HTML, CSS, or JavaScript. These files come together and make up the web page of the site. Suppose that you visited the page yesterday and then stored these files on your browser.

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” 

ExpiresByType…:

  • text/html “access plus 8200 seconds” 
  • image/javascript “access plus access plus 1 month 2 weeks” 
  • 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

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 ##

<IfModule mod_expires.c>

ExpiresActive On

# Images

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”

 # Video

 ExpiresByType video/mp4 “access plus x year

——————————————————————– “

 ExpiresByType video/mpeg “access plus x year”

# CSS, JavaScript

 ExpiresByType text/javascript “access plus x month”

 ExpiresByType application/x-shockwave-flash “access plus x month” 

</IfModule>

## 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

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

What files are saved in the cache?

As we mentioned above, there are a lot of file types that you can prefer. Let’s give some examples. 
images: jpg-jpeg-gif-png, HTML, CSS, PDF, Javascript, Shockwave-flash, Favicon/ico.

What are the primary benefits of adding expires headers?

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.

What are WordPress plugins?

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.

What are the best caching plugins for 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)

Is there a relationship between expires headers and SEO?

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.



The post How to Add Expires Headers is republished from Dopinger Blog

Yorumlar

Bu blogdaki popüler yayınlar

Minimizing CSS, HTML, and JavaScript Files 

How to Detect Which Theme & Plugin a Website Is Using

Responsive Web Design