HowTo: Tune your wordpress – these .htaccess tricks speed up your website!

Google PageSpeed Insights told you, that your wordpress website is too slow? Need better performance? These .htaccess settings for your apache speed up your website!

What you have to do is simply tune up your htaccess, inject gzip and discard ballast.
Gzip and Deflate Compression shrink overweight pounds of the website, as well as serve cache and expire sites via htaccess in a optimal way.

This is how it works:
I have been looking for an optimal htaccess which takes account of all the recommendations of Page Speed. First we need to setup the apache2 modules, i am using a ubuntu/debian system:

# a2enmod headers
Enabling module headers.

# a2enmod expires
Enabling module expires.

# a2enmod deflate
Considering dependency filter for deflate:
Module filter already enabled
Module deflate already enabled

# service apache2 restart
* Restarting web server apache2                                                                                                   [ OK ]

 

These are the suggestions made by Google for a optimized .htaccess file. Just add them to your .htaccess file on your domain root.

 

# compress
<IfModule mod_deflate.c>
 <FilesMatch "\.(js|jpg|jpeg|gif|png|css|txt|html)$">
 ExpiresActive on
 ExpiresDefault "access plus 1 month"
 SetOutputFilter DEFLATE
 </FilesMatch>
</IfModule>

<IfModule mod_gzip.c>
 mod_gzip_on Yes
 mod_gzip_dechunk Yes
 mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
 mod_gzip_item_include handler ^cgi-script$
 mod_gzip_item_include mime ^text/.*
 mod_gzip_item_include mime ^application/x-javascript.*
 mod_gzip_item_exclude mime ^image/.*
 mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

# cache
<IfModule mod_expires.c>
 ExpiresActive On
 ExpiresByType text/css "access plus 1 month"
 ExpiresByType text/javascript "access plus 1 month"
 ExpiresByType text/html "access plus 1 month"
 ExpiresByType application/javascript "access plus 1 month"
 ExpiresByType application/x-javascript "access plus 1 month"
 ExpiresByType application/xhtml-xml "access plus 600 seconds"
 ExpiresByType image/gif "access plus 1 week"
 ExpiresByType image/jpeg "access plus 1 week"
 ExpiresByType image/png "access plus 1 week"
 ExpiresByType image/x-icon "access plus 1 month"
</IfModule>

good luck and have fun!

1 thought on “HowTo: Tune your wordpress – these .htaccess tricks speed up your website!”

Leave a Comment