The Bluehost problem
Compressing files using Apache is usually fairly trivial,
some simple modifications to your
file will often suffice
, but I found that nothing I tried was working. In the end I decided to contact customer support, who told me the following
The way gzip works is that when certain criteria are reached with the server resources, gzip will be enabled and start compressing the sites as needed. Even with the code in the .htaccess file, that's not actually something that you will be able to configure on the account.
Their definition of "as needed" being "none of the time". I slumped into my chair, loathing Google's Page Speed result, and knowing that, short of leaving Bluehost, nothing could be done. Until...
Cloudflare - free CDN provided by Bluehost
My reaction to Bluehost's hopelessness, was to search for a free Content Delivery Network (CDN), which would serve my static content for me - minified, gzipped and quickly. I quickly came across Cloudflare , who offer a reduced plan for free. Whilst it looked great, it also seemed a bit of hassle to set up, and so I disregarded the idea until I noticed that Bluehost are a Cloudflare hosting partner . Setting it up for your site is really straight forward:
- Visit Bluehost and sign into cPanel
- Once logged in, find the link to CloudFlare from the "Domains" section
This will take you to a list of your domains hosted with Bluehost, and simply click "Activate" to get started. This will add a
CNAMEDNS record to redirect your
www.traffic to the cloudflare servers.
More than likely these short steps will be sufficient, and you'll find your site's static content will be automatically cached, GZipped and minified. By clicking on the "advanced" link you can make further configurations.
This site runs on Django, and Bluehost doesn't play nicely with Django.
Getting it to work is a bit of a pain
, and requires
. You'll then need to make sure that all your traffic is passed to the FastCGI script by adding some
As previously mentioned, CloudFront's servers take over all
traffic, and all non-
traffic is redirected. This is achieved by
, which happened to be conflicting with the ones I set up to use Django. This resulted in the following:
All traffic was channelled through my fastCGI script, e.g.
mysite.fcgiusing a Rewrite Condition
www.traffic was being redirected to
Combining the two, a request to
mysite.comresulted in a redirect to
Good news , the fix is simple: just make sure that the CloudFlare Rewrite Condition comes before anything else, and voila, problem solved!
Make sure to let search engines know that you'd prefer your visitors to access the
version of your site, which will avoid as many unwanted redirects as possible in the future.