From my previous experience with Sprockets, Sinatra and Rack::Deflater , I was sure that I was just another use Rack::Deflater from what I wanted.
I changed config.ru to this:
use Rack::Static, :urls => ["/images", "/js", "/css"], :root => "public" use Rack::Deflater run lambda
and I was able to verify that the responses were sent by gzipped:
$ curl -H 'Accept-Encoding: gzip' http://localhost:9292 | file - /dev/stdin: gzip compressed data
but not for static assets in /css , /js or /images :
$ curl -H 'Accept-Encoding: gzip' http://localhost:9292/css/bootstrap.min.css | file - /dev/stdin: ASCII English text, with very long lines
And when I realized that this is the standard intermediate stacks - Rack :: Static intercepts the call of static files and thus skips the next stack! This is why it worked for public/index.html , but not for assets.
The following config.ru (note that use Rack::Deflater now preceded by use Rack::Static ):
use Rack::Deflater use Rack::Static, :urls => ["/images", "/js", "/css"], :root => "public" run lambda { |env| [ 200, { 'Content-Type' => 'text/html', 'Cache-Control' => 'public, max-age=86400' }, File.open('public/index.html', File::RDONLY) ] }
Verified with
$ curl -H 'Accept-Encoding: gzip' http://localhost:9292/css/bootstrap.min.css | file - /dev/stdin: gzip compressed data, from Unix