Want to say hi?

Got a project you’d like to chat about, or just want to shoot the breeze? I’d love to hear from you! Feel free to use any of the methods below.

52 Goetre Fawr, Radyr, Cardiff, CF15 8EU
07969 645599
info@joshbedford.com

Josh Bedford

Speed up your WordPress site through your .htaccess file
Htaccess Speed Boost

Speed up your WordPress site through your .htaccess file

Here’s a very easy solution to gain some quick speed wins and increase your GTMetrix and Google site speed scores.

I use the boilerplate below on all my sites. It configures Etags, Gzips (if available) sets far future expires for files and images (one of the most common errors to be flagged up), and more.

You can try W3 Total Cache to help with this but I sometimes find it over kill and it can conflict at times with certain plugins.

Autoptimize works great on many themes and gives you added site speed without a massively bloated plugin. With it you can compress your CSS, HTML and Javascript but make sure that they are only being used on the pages they need to be. Plugins add CSS and Javascript pretty much everywhere even though you might only use it on the home page (for example a homepage slider) so you can deregister unnecessary CSS and scripts in your theme’s functions.php file as well but plugins like Autoptimize will do a great job most times. Just be aware that it’s easy to break your site by going too crazy on the minification, so be cautious!

The Boilerplate

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Header unset ETag  
FileETag None

# BEGIN Expire headers  
<ifModule mod_expires.c>  
    ExpiresActive On  
    ExpiresDefault "access plus 2592000 seconds"  
    ExpiresByType image/x-icon "access plus 2592000 seconds"  
    ExpiresByType image/jpeg "access plus 2592000 seconds"  
    ExpiresByType image/png "access plus 2592000 seconds"  
    ExpiresByType image/gif "access plus 2592000 seconds"  
    ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"  
    ExpiresByType text/css "access plus 604800 seconds"  
    ExpiresByType text/javascript "access plus 216000 seconds"  
    ExpiresByType application/javascript "access plus 216000 seconds"  
    ExpiresByType application/x-javascript "access plus 216000 seconds"  
    ExpiresByType application/xhtml+xml "access plus 600 seconds"
    ExpiresByType text/html "access plus 1 day"
</ifModule>  
# END Expire headers

# BEGIN Cache-Control Headers  
<ifModule mod_headers.c>  
    <filesMatch "\.(ico|jpe?g|png|gif|swf)$">  
        Header set Cache-Control "public"  
    </filesMatch>  
    <filesMatch "\.(css)$">  
        Header set Cache-Control "public"  
    </filesMatch>  
    <filesMatch "\.(js)$">  
        Header set Cache-Control "private"  
    </filesMatch>  
    <filesMatch "\.(x?html?|php)$">  
        Header set Cache-Control "private, must-revalidate"  
    </filesMatch>  
</ifModule>  
# END Cache-Control Headers

# BEGIN GZIP (May not work on all servers)
# mod_gzip compression (legacy, Apache 1.3)
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|xml|txt|css|js)$
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>
# END GZIP

# DEFLATE compression
<IfModule mod_deflate.c>
# Set compression for: html,txt,xml,js,css
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
# Deactivate compression for buggy browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
# Set header information for proxies
Header append Vary User-Agent
</IfModule>
# END DEFLATE
Josh Bedford info@joshbedford.com

<p>WordPress Specialist and front-end developer. I like ice hockey, cycling, sarcasm and cake. In my spare time I visit new places with my wife and collect vinyl (the records, not the flooring).</p>

No Comments

Post a Comment

Say hello!

info@joshbedford.com