WordPress Tutorials

Setting to Leverage Browser Caching on GoDaddy Hosting doesn’t work

April 8, 2016

You may all know how to set expired headers for static files using .htaccess file. There are a lot of tutorial online. The purpose is to tell browser to cache static content, such as CSS, JS or image files, for a period of time. By doing that, browsers do not have to query the files again, thus decrease loading time of a page. Google PageSpeed Insights measures this parameter and give you bad rate if you do not utilize this setting.

Basically, your .htaccess file should have this content

# 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

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
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

However, it may not work if you use GoDaddy Hosting. Due to various default settings of GoDaddy, they disable many features and you cannot change via .htaccess. To make above settings work, you can add this on top of the .htaccess file

Header unset Pragma
FileETag None
Header unset ETag

<IfModule pagespeed_module>
ModPagespeed on
# using commands,filters etc
</IfModule>

Well yes, you have to disable Etag Header setting for static content, and turn on pagespeed_mobule. I’m sure that will help you to increase Google PageSpeed Insight grade.

You Might Also Like