use Rack::Cache
use Rack::Deflater
use ActionDispatch::Static
use Rack::Lock

And content served were still gzipped. However, assets were not compiled(minified) as pre-compilation failed. A manual rake precompile::asets also does not help.

So, I'm assuming ActionDispatch::Static is not available during pre-compilation of assets. So I tried to insert Rack::Deflater before Rack::Lock and now my assets are compiled without any error message but content served is not gzipped.

So, what do I need to do, to both gzip and compile my assets? What am I missing? Thanks.

the ActionDispatch::Static middleware is only used when serve_static_assets is set to true. Heroku actually injects this config to override whatever you set anyway (see the Injecting rails3_serve_static_assets log message when you deploy), but I'm not sure at what stage in the deploy this happens.

So it's likely that you don't have static asset serving enabled when the assets:precompile runs (note this is just a guess, I'm not on Rails 3.1 yet so I could be wrong)

I would recommend against membLoper's suggestion of adding it manually in your rackup file:

it's not needed as explained above

your middleware that is relevant to your app should really be injected as you had originally tried in your application.rb