GithubHelp home page GithubHelp logo

mscifo / turbo-sprockets-rails3 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ndbroadbent/turbo-sprockets-rails3

0.0 2.0 0.0 420 KB

Speeds up your Rails 3 assets:precompile by only recompiling changed files, and only compiling once to generate all assets

License: MIT License

turbo-sprockets-rails3's Introduction

Turbo Sprockets for Rails 3.2.x

Build Status

  • Speeds up your Rails 3 rake assets:precompile by only recompiling changed assets, based on a hash of their source files
  • Only compiles once to generate both fingerprinted and non-fingerprinted assets

Disclaimer

turbo-sprockets-rails3 can now be considered relatively stable. A lot of compatibility issues and bugs have been solved, so you shouldn't run into any problems. However, please do test it out on your local machine before deploying to a production site, and open an issue on GitHub if you have any problems. By using this software you agree to the terms and conditions in the MIT license.

Usage

Just drop the gem in your Gemfile, under the :assets group:

group :assets do
  ...
  gem 'turbo-sprockets-rails3'
end

Run bundle to install the gem, and you're done!

Test it out by running rake assets:precompile. When it's finished, you should see a new file at public/assets/sources_manifest.yml, which includes the source fingerprints for your assets.

Go on, run rake assets:precompile again, and it should be a whole lot faster than before.

Enjoy your lightning fast deploys!

Removing Expired Assets

turbo-sprockets-rails3 provides a Rake task called assets:clean_expired. You can run this task after assets:precompile to remove outdated assets.

If you use this rake task, you must set config.assets.handle_expiration to true in config/environments/production.rb. This makes sure that asset modification times are updated properly before assets:precompile, so that the clean_expired task knows which assets are safe to remove.

An asset will be deleted if it is no longer referenced by manifest.yml, and hasn't been actively deployed for more than a day (default).

You can configure the expiry time by setting config.assets.expire_after in config/environments/production.rb. An expiry time of 2 weeks could be configured with the following code:

config.assets.expire_after 2.weeks

Versioning

The gem needs to support multiple changes to Rails and sprockets, so the following versioning is used:

  • Rails 3.2.0 to 3.2.8 uses turbo-sprockets-rails3 0.2.x
  • Rails 3.2.9 and higher uses turbo-sprockets-rails3 0.3.x

Compatibility

Fully compatible.

Fully compatible starting from version 0.8.0.

gem 'wicked_pdf', '>= 0.8.0'

Please let me know if you have any problems with other gems, and I will either fix it, or make a note of the problem here.

Deployments

Capistrano

turbo-sprockets-rails3 should work out of the box with the latest version of Capistrano.

Heroku

I've created a Heroku Buildpack for turbo-sprockets-rails3 that keeps your assets cached between deploys, so you only need to recompile changed assets. It will automatically expire old assets that are no longer referenced by manifest.yml after 7 days, so your public/assets folder won't grow out of control.

To create a new application on Heroku using this buildpack, you can run:

heroku create --buildpack https://github.com/ndbroadbent/heroku-buildpack-turbo-sprockets.git

To add the buildpack to an existing app, you can run:

heroku config:add BUILDPACK_URL=https://github.com/ndbroadbent/heroku-buildpack-turbo-sprockets.git

Compiling Assets on Your Local Machine

You can also compile assets on your local machine, and commit the compiled assets. You might want to do this if your local machine is a lot faster than the Heroku VM, or if you also want to generate other files, such as static pages. When you push compiled assets to Heroku, it will automatically skip the assets:precompile task.

I've automated this process in a Rake task for my own projects. The task creates a deployment repo at tmp/heroku_deploy so that you can keep working while deploying, and it also rebases and amends the assets commit to keep your repo's history from growing out of control. You can find the deploy task in a gist at https://gist.github.com/3802355. Save this file to lib/tasks/deploy.rake, and make sure you have added a heroku remote to your repo. You will now be able to run rake deploy to deploy your app to Heroku.

Debugging

If you would like to view debugging information in your terminal during the assets:precompile task, add the following lines to the bottom of config/environments/production.rb:

config.log_level = :debug
config.logger = Logger.new(STDOUT)

turbo-sprockets-rails3's People

Contributors

ndbroadbent avatar aaronjensen avatar oggy avatar gnovos avatar ryana avatar pwnall avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.