Set your headers!

I’m now setting expiry headers and gzipping content on this website. I was amazed at how easy it is to get an ‘A’ rating on YSlow.

YSlow Results

I’ve used the following .htaccess rules for my website which I pulled from HTML5 Boilerplate and modified. I suggest you do the same as the boilerplate is a great starting point - it includes almost every .htaccess rule you will ever need, and then some.

# Expiries Headers
<IfModule mod_expires.c>
  ExpiresActive on
  ExpiresByType image/x-icon              "access plus 1 week" 
  ExpiresByType image/gif                 "access plus 1 week"
  ExpiresByType image/png                 "access plus 1 week"
  ExpiresByType image/jpg                 "access plus 1 week"
  ExpiresByType image/jpeg                "access plus 1 week"
  ExpiresByType text/css                  "access plus 3 days"
  ExpiresByType application/javascript    "access plus 3 days"
  ExpiresByType text/javascript           "access plus 3 days"
  <IfModule mod_headers.c>
    Header append Cache-Control "public"
  FileETag None

# Gzip Compression
<IfModule mod_deflate.c>
<IfModule mod_setenvif.c>
  <IfModule mod_headers.c>
    SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s,?\s(gzip|deflate)?|X{4,13}|~{4,13}|-{4,13})$ HAVE_Accept-Encoding
    RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
<IfModule filter_module>
  FilterDeclare   COMPRESS
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type /text/(html|css|javascript|plain|x(ml|-component))/
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type /application/(javascript|json|xml|x-javascript)/
  FilterChain     COMPRESS
  FilterProtocol  COMPRESS  change=yes;byteranges=no
<IfModule !mod_filter.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
  AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript 
  AddOutputFilterByType DEFLATE text/xml application/xml text/x-component

These settings will improve the speed of your website significantly, and as it’s so easy, there’s no reason not to. I almost wish there were sensible defaults built into servers, imagine how much faster the internet would be.

Notice: Array to string conversion in /var/www/ on line 22

Fatal error: Uncaught Error: Function name must be a string in /var/www/ Stack trace: #0 /var/www/ tags(Object(page)) #1 /var/www/ require('/var/www/joshem...') #2 /var/www/ tpl::loadFile('/var/www/joshem...', Array, true) #3 /var/www/ tpl::load('post', Array, true) #4 /var/www/ site->load() #5 /var/www/ require_once('/var/www/joshem...') #6 {main} thrown in /var/www/ on line 22