Speed up Wordpress via htaccess
Friday 6th of October 2017
Wordpress is a great CMS which powers over 25% of the world's websites but it can be little slow and sluggish just due to the “bloat” that is installed on every installation.
There are a number of caching plugins which you can install to help speed the site up by adding things such as Gzip compression, however, we always try and install as little plugins as possible. Why? Well, plugins add an extra security risk and again add to the bloat of your install.
A much cleaner way is to add some code to your websites .htaccess file.
You can find this file within the folder where WordPress is installed or if you are using Yoast SEO plugin you can edit the file using the editor under tools.
A quick word of warning tho. If you put incorrect code within a .htaccess file you could potentially break your site. For this reason, we recommend taking a backup of it first and making the changes via cPanel or FTP as if you change it via a plugin and break your site you won't be able to get back in to change it back!
So let's get going.
Find your htaccess file and at the bottom put this code to enable Gzip compression
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddType x-font/otf .otf
AddType x-font/ttf .ttf
AddType x-font/eot .eot
AddType x-font/woff .woff
AddType image/x-icon .ico
AddType image/png .png
Then to add expires headers so that people who visit your site again are served a cached version of images add this code:
## EXPIRES CACHING ##
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 application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
## EXPIRES CACHING ##
Your site will now be running much faster than before!