9

I'm working to install Jammit on my Rails 3 app and then to deploy to Heroku.

I installed the Jammit Gem, and configured assets.yml just fine, it works on dev. But when I pushed to heroku, the files were 404'ing.

Jammit's Usage instructions say: "You can easily use Jammit within your Rakefile, and other scripts:

require 'jammit'
Jammit.package!

I'm not following where/how that works. Running Jammit in my sites command like on the Mac yields a command not found.

Any Jammit users able to help me understand how to move to production with Jammit?

Thanks

5 Answers 5

6

I'm using jammit on a Rails 3.0.7 app, on Heroku

gem "jammit", :git => "git://github.com/documentcloud/jammit.git"

I have this in a rake file, to package up the assets before I commit/deploy

desc 'jammit'
  task :jam  => :environment do
  require 'jammit'
  Jammit.package!
end

And this in .git/hooks/pre-commit so it is done automatically

echo "jamming it"
rake jam
git add public/assets/*
git add public/javascripts/*

By default, the expires time on Heroku was only 12hrs, to increase it (because I have a cache-busting scheme that I am confident in) I put this in config/initializers/heroku.rb

module Heroku
  class StaticAssetsMiddleware
    def cache_static_asset(reply)
      return reply unless can_cache?(reply)
      status, headers, response = reply        
      headers["Expires"] = CGI.rfc1123_date(11.months.from_now)
      build_new_reply(status, headers, response)
    end
  end
end

To decrease the load on my Heroku Rails server, I am also using a free account at CloudFlare which provides a lightweight, reverse-proxy/cdn, with some decent analytics and security features.

When I get around to caching common content, this thing is really gonna scream!

3

You could, as I do, use jammit force to pack your assets, upload everything to s3 and define an asset host(s) in rails. This has the added advantage of keeping your slug smaller and more responsive as you can add your public directory to .slugignore .

Alternatively you'll need to work out how to make the heroku version work due to the read only file system.

1
  • 1
    You host your assets off S3? Why? It's not a CDN, I could see doing that with CloudFront, but am curious why S3. Dec 10, 2010 at 20:42
2

You can also use a git pre-commit hook to ensure your assets are packaged prior to pushing to heroku (or any server). See https://gist.github.com/862102 for an example. You can copy that file to .git/hooks/pre-commit in your project directory.

1

this one is the solution

https://github.com/kylejginavan/heroku_jammit

0

Heroku has a read-only file system, so Jammit is unable to actually store compressed and minified CSS/JS files.

Here is a very good article on the challenge of asset packaging on heroku: http://jimmycuadra.com/posts/the-challenge-of-asset-packaging-on-heroku

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.