documentcloud / jammit

Industrial Strength Asset Packaging for Rails
http://documentcloud.github.com/jammit/
MIT License
1.16k stars 197 forks source link

JS and CSS compressed on every call to Rails production application #66

Closed dbarros closed 14 years ago

dbarros commented 14 years ago

I have a Rails 3 app, running under Mongrel. When in development, all works as expected. Each CSS and JS file included individually.

But in production, the CSS and JS files are being concatenated and compressed every time I go to a URL in the Rails app.

The following happens when I hit the root URL. If I go to the URL twice, the following appears twice. As you can see, the main.css and main.js files are being generated every time:

Started GET "/" for 127.0.0.1 at Tue Sep 14 16:20:04 +1000 2010
  Processing by HomeController#index as HTML
Rendered shared/_html_head.html.erb (1.2ms)
Rendered shared/_search.html.erb (0.1ms)
Rendered shared/_account_details.html.erb (0.0ms)
Rendered home/index.html.erb within layouts/application (2.4ms)
Completed 200 OK in 3ms (Views: 3.0ms | ActiveRecord: 0.2ms)

Started GET "/assets/main.css?1284445191" for 127.0.0.1 at Tue Sep 14 16:20:04 +1000 2010
  Processing by Jammit::Controller#package as HTML
  Parameters: {"extension"=>"css", "package"=>"main", "1284445191"=>nil}
Rendered text template (0.0ms)
Completed 200 OK in 666ms (Views: 1.6ms | ActiveRecord: 0.3ms)

Started GET "/assets/main.js?1284445199" for 127.0.0.1 at Tue Sep 14 16:20:05 +1000 2010
  Processing by Jammit::Controller#package as */*
  Parameters: {"extension"=>"js", "1284445199"=>nil, "package"=>"main"}
Completed 200 OK in 7626ms (Views: 0.3ms | ActiveRecord: 0.2ms)                

This is my assets.yml file:

compress_assets: on
gzip_assets: off
javascript_compressor: closure
package_assets: on

javascripts:
  main:
    - public/javascripts/application.js
    - public/javascripts/**/*.js

stylesheets:
  main:
    - public/stylesheets/reset.css
    - public/stylesheets/text.css
    - public/stylesheets/960.css
    - public/stylesheets/screen.css
    - public/stylesheets/jquery-ui/jquery-ui-1.8.4.custom.css

Is there something I need to do so that (in production) the main.css and main.js files are generated once?

Has this maybe have something to do with me using Mongrel and not Apache/Nginx: where I would set the HTTP Expires header information as prescribed in the Jammit docs?

Any help would be appreciated.

Thanks.

dbarros commented 14 years ago

Never mind. Minutes after posting the question (although I had tried to find a solution for quite a while), by chance I came across the solution.

For anyone interested, I needed to set the following in config/environments/production.rb:

config.serve_static_assets = true
jashkenas commented 14 years ago

dbarros: Glad you got it solved, but -- yikes! Are static assets not served by default in Rails 3?

dbarros commented 14 years ago

jashkenas: That's right. Seems like the default is to not serve static assets. This is from config/environments/production.rb:

config.serve_static_assets = false
jashkenas commented 14 years ago

FYI, I've pushed a new version of Jammit, and added a warning about Rails 3 and serve_static_assets to the documentation.

dbarros commented 14 years ago

Excellent! Hopefully it may help others faced with this "quirk". Thanks.