When using the native gzip feature (activate :gzip), what is the best way to serve them when hosting on Heroku using Rack::TryStatic?
I’m having a bit of a headache trying to come up with a solution for that, everything out there seems to consider Rack::Deflater as the defacto way, but I’d like to just serve the pre-generated gz files, instead of zipping them on the fly, like Deflater does.
Here. I wrote a Rack app that works with Middleman’s .gz files. It probably needs to check the request headers include the right Accept-Encoding before serving a GZipped response, but I’ll leave that as an exercise for the reader.
Thanks! I would love to do something like that, but I’m a little reluctant to dive in. Using this approach isn’t something I would ever use personally, so I worry that I wouldn’t have much motivation to keep it well looked-after.
The truth is, I think people should stick to Rack::Deflater or handle the gzipping at a higher level (e.g. nginx/Apache). Both will not introduce any noticeable delay to server processing time.
If it’s performance anyone’s concerned about, they should measure it. I suspect anyone who tries won’t find any significant impact. There are far better places to optimise server load times.
Gzipping is not CPU intensive and the response is streamed, so it’s not as if the whole file has to be gzipped before it can start being sent to the client or anything.
Here’s a nice StackOverflow response addressing this:
@Aupajo: last time I’ve tried using Rack::Deflater on Heroku it was adding a significant lag on static assets to the point where it wasn’t worth it. Each dyno is quite weak in terms of CPU and IO.