Leverage Browser Caching with GoDaddy and WP Engine

I searched the web far and wide to figure out exactly what code should go into an .htaccess file on a GoDaddy shared server in order to remove Google Pagespeed’s Leverage Browser Caching warning. While the code is out there and wasn’t too difficult to locate, GoDaddy’s own support pages had code that killed the entire site (ie, 500 error) and others left a few vital filetypes out (at least as the web stands in 2014). Turns out the following also works with WP Engine. Update: Actually WP Engine runs NGINX so .htaccess files don’t typically have an effect, however WP Engine also seems to just take care of this stuff automatically.

So without much more ado, here’s what you’ll want to paste to the top of your .htaccess file (I put it above the # BEGIN WordPress code).

<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 image/svg+xml "access 1 year"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 year"
</IfModule>

There we cache our image files on the first few lines (including the elusive SVG, which is where it’s at these days, even with WordPress), then any PDF files, Javascript, CSS and finally our favicon. Oh and then finally finally, anything else. You can change 1 year to 1 month or 24 hours, etc. if you’d like.

Note that you may still get that message if, for example, you’re using Google Analytics, which sets its own code to expire in 2 hours…not sure why Google puts up error messages for its own .js file but the code above will at least resolve issues with files on your own server.

I have a similar tutorial for Pagespeed’s Enable compression warning for GoDaddy, and one for MediaTemple, too. Or do yourself a favor and ditch all of this tinkering by hosting your WordPress site with WPEngine Flywheel!

Up Next: Enable Compression on GoDaddy Shared Hosting