As a WordPress website owner, adding expires header can help speed up your website. It works in two ways: reduces the number of HTTP requests sent to the server and reduces the number of files that need to be downloaded as a web cache. 

This article will explain two simple methods in adding expires header in your WordPress website; with and without a plugin.

With a Plugin

Caching plugins are the best choice because they let you enable browser caching and expires headers in just several simple steps. The steps below are done with W3 Total Cache.

  1. Click Performance and click on Browser Cache.
  2. Scroll down to the General sub-box.
  3. Tick the option “Set expires headers.”
  4. Scroll down to the CSS & JS section, tick the box next to “Set expires header”, and enter your Expires header lifetime value in seconds. By default, this value is 31.536.000 seconds or 365 days. You can change this as your desire.
  5. Repeat this step for the HTML & XML and Media & Other Files sections.
  6. Lastly, click Save all settings to save all of the changes.

Without a Plugin

In this option, adding expires headers to a WordPress website is done manually. Below, we have outlined the steps for Apache and Nginx servers:

Add Expires Headers on an Apache Server

  1. Connect to your server through your hosting panel or with an FTP client.
  2. Navigate to public_html.
  3. Find your .htaccess file. Note: This may require you to reveal hidden files in order to access some of your most private data.
  4. Open .htaccess in your hosting panel file editor, or download the file and open it in a code editor.
  5. Add the following code snippet before the line #END WordPress:

ExpiresActive On

ExpiresByType text/html “access 1 month”

ExpiresByType text/css “access 1 month” 

ExpiresByType text/javascript “access 1 month”

ExpiresByType text/x-javascript “access 1 month”

ExpiresByType image/jpeg “access 1 year”

ExpiresByType image/jpg “access 1 year”

ExpiresByType image/png “access 1 year” 

ExpiresByType image/svg “access 1 year”

ExpiresByType image/gif “access 1 year”

ExpiresByType application/pdf “access 1 month” 

ExpiresByType application/javascript “access 1 month”

ExpiresByType application/x-javascript “access 1 month”

ExpiresByType application/xhtml+xml “access 1 month”

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

ExpiresByType image/x-icon “access 1 year”

ExpiresDefault “access 4 days”

Other file types expire after different periods. Depending on your content, you may want to change the expiry date in your HTTP response header.

  1. Save the file (and re-upload it via FTP if necessary).

Add Expires Headers on an Nginx server

  1. Open your configuration file (conf) in your server panel editor or a code editor. Note: There are multiple ways to access and edit this file, so you can reach out to your hosting provider for help accessing the file.
  2. Add the following code snippet within the server block:
      location ~* \.(jpeg|jpg|png|svg|gif)${
      expires 365d;

    This sets your image assets to expire after one year. To set expiration periods for a specific time, edit your code and insert the appropriate file extension names and insert a different period as you wish. Here’s what you’d add to set your HTML, CSS, and JavaScript files to expire after 30 days:
     location ~* \.(html|css|js)${
      expires 30d;
  3. After making these changes, be sure to save the changes to your Nginx configuration. Then you can restart it.

Other than those mentioned methods, plenty of techniques can be done to speed up your website. We have a new package that guarantees to speed up your WordPress site to load in 2-3s, with only a $79 fixed fee, done in 72h. Results guaranteed or full refund.

Get a speeeeedy website now

2-3 second load time or your money back, no questions asked.

Add the following code snippet before the line #END WordPress:

                        ExpiresActive On

ExpiresByType text/html "access 1 month"

ExpiresByType text/css "access 1 month" 

ExpiresByType text/javascript "access 1 month"

ExpiresByType text/x-javascript "access 1 month"

ExpiresByType image/jpeg "access 1 year"

ExpiresByType image/jpg "access 1 year"

ExpiresByType image/png "access 1 year" 

ExpiresByType image/svg "access 1 year"

ExpiresByType image/gif "access 1 year"

ExpiresByType application/pdf "access 1 month" 

ExpiresByType application/javascript "access 1 month"

ExpiresByType application/x-javascript "access 1 month"

ExpiresByType application/xhtml+xml "access 1 month"

ExpiresByType application/x-shockwave-flash "access 1 month"

ExpiresByType image/x-icon "access 1 year"

ExpiresDefault "access 4 days"                    

Book a call

Get more customers!

Digital Marketing solution that helps to get more site visitors and increase sales

Signup to our Newsletter