Question

I have an app on heroku with a custom domain. www.mydomain.com has a cname record for myapp.herokuapp.com. mydomain.com has a 301 redirect to www.mydomain.com. I am on the Heroku Ceder stack. I enabled gzip compression using heroku_rails_deflate gem. The server does not respond with a gzip asset for requests using www.mydomain.com.

*EDIT*** when I originally posted my 301 redirect was not working properly. Now when I curl mydomain.com I get a 301 response.


curl -I -H 'Accept-Encoding: gzip' http://myapp.herokuapp.com/assets/application-7cbaf74d14cc5a5ab54262a43e4xxxxx.css 

and

curl -I -H 'Accept-Encoding: gzip' http://mydomain.com/assets/application-7cbaf74d14cc5a5ab54262a43e4xxxxx.css

both result in:

Age: 1390
Cache-Control: public, max-age=2592000, no-transform
Content-Encoding: gzip
Content-length: 19377

however

curl -I -H 'Accept-Encoding: gzip' http://www.mydomain.com/assets/application-7cbaf74d14cc5a5ab54262a43e4xxxxx.css

results in:

Age: 7378
Cache-Control: public, max-age=2592000
Content-length: 119016

furthermore, rack cache seems to be maintaining a separate cache for each url. Logs show:

cache: [HEAD /assets/application-7cbaf74d14cc5a5ab54262a43e4xxxxx.css] miss, store

for an apex domain request after it had already served a fresh request for the same asset using myapp.herokuapp.com

EDIT: here is my config.ru:

require ::File.expand_path('../config/environment',  __FILE__)
run Rails.application

!**Another Addition***! nslookup using opendns nameservers shows that the two different urls use two different ip addresses even though one is a cname for the other (I'm no dns expert) !*!

Is there a way to get heroku to treat the different urls the same? If not, is it possible to get gzip working for all of them? Thanks in advance for any tips or solutions.

Was it helpful?

Solution

You'll want to add use Rack::Deflater to your config.ru in order to get Heroku to serve compressed assets.

Your config.ru would look something like this:

require ::File.expand_path('../config/environment',  __FILE__)
use Rack::Deflater
run Rails.application

There is a good discussion on either using Rack::Deflater or some alternatives in order to serve compressed assets on Heroku, but it seems people keep coming back to Rack::Deflater.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top