To add expires headers in your WordPress blog without using a plugin
- Go to the .htaccess file (it is normally located in the public.html folder) or if you are using the Yoast SEO plugin access the .htaccess file from WordPress admin via Yoast>Tools>file editor>.htaccess file
- Copy and paste the expire headers code below the .htaccess file
# EXPIRES HEADERS START
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access 1 year"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/webp "access 1 year"
ExpiresByType image/svg+xml "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/javascript "access 1 month"
ExpiresByType text/html "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/pdf "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresDefault "access 1 month"
</IfModule>
# END EXPIRES HEADERS
What are expires headers? Expires headers is an HTTP header directive that tells a browser to download and store a web page's resources to the site visitor’s local computer browser for a set time. It also instructs the browser after how long the stored resources should be updated.
For example, if you visit a Facebook page for the first time, cached resources like (images, CSS, and JavaScript files) will be downloaded and stored in your local computer's browser. The next time you visit the same page, the resources will not be downloaded again from the page but will be loaded from the browser you used. This increases page load speed and saves data usage.
If you have files that frequently change, then it is advisable to reduce cache time or ignore browser cache. For example, HTML files.