How to Add Expires Headers in WordPress

Published by Vijay Kumar || Listed Under:

Expires headers specifies a time far enough to load images, CSS, and JavaScript files in the future for returning visitor. When a user visits your website for the first time there will be no change in load time. If a user visits again, your site load time will decrease dramatically and the user enjoys that blazing speed.

The main advantage of adding far-future expires headers to your WordPress site is browser caches CSS/Images/JS file and loads user-requested page by reducing the HTTP requests. Ultimately user enjoys fast loading websites, so without waiting much, just add the following code to your .htaccess file. Make sure that, the following code should be added to the .htaccess file properly.

<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>

Tip: If your CSS and JS files don't change often then you can set longer expiry date. You can also add expires headers in WordPress with the most popular cache plugin of W3 total cache.

Note: You can't set expires headers for Google fonts, Google AdSense, Analytics, and other third-party resources.

linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram