Add the expires header

To speed up your WordPress website, it is very useful to add the expires header to the .htaccess file.

With the expires header you tell the browsers that the files that are loaded by your website, will not change for the predefined period. The browser can cache these files en reuse them when the website is revisited.

Caching saves a lot of load time because several files won’t have to be loaded from the web server. Files like images, CSS and Javascript.

With the code below you tell the visitor’s browser which files can be cached and for how long.

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"

To use this code, open the .htaccess file in the root of the WordPress installation. Copy the code and paste this in .htaccess. Save the file on the web server and you’re done. To check the results, you just have to visit your website. You can measure the results with a tool like GTMetrix.

Always backup the .htaccess before you start changing it!

Ronald Heijnes
Ronald Heijnes

Since 2008 I keep myself busy with the functionality, management, maintenance and performance of self hosted WordPress. I like to share this knowledge. All in my spare time!

Articles: 44

Leave a Reply

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