Coder Social home page Coder Social logo

braverails / heroku_rails_deflate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mattolson/heroku_rails_deflate

0.0 2.0 0.0 375 KB

Activate Rack::Deflate and serve up precompiled, gzipped assets on Heroku

License: MIT License

Ruby 100.00%

heroku_rails_deflate's Introduction

heroku_rails_deflate

The Heroku Cedar stack is not fronted by an asset server such as Varnish or nginx, and there is no automatic provision for using gzip compression for HTTP transfers. At the same time, the Rails 3.2 asset pipeline spends a lot of CPU cycles creating highly compressed versions of all our static assets. It would be great to use them!

This gem activates Rack::Deflate for all requests. But the real coolness is the custom middleware that checks for the .gz version of precompiled assets and serves them up for you. We also eliminate conflict with Rack::Deflate by telling it not to compress these already compressed files. We also provide a sensible default for the Cache-Control header for these files. If you are using the asset digest in the filename (and you should), there is no reason why we can't set very high max-age, so we set it to one year by default.

You should see a nice performance boost from the installation of this gem, without any additional work on your part. After you get done with this, you could take it to the next level by adding a CDN such as AWS CloudFront.

Installation

  • Add the gem to your app
  gem 'heroku_rails_deflate', :group => :production
  • Make sure asset caching is configured correctly in environments/production.rb:
  config.serve_static_assets = true
  config.assets.compress = true
  config.assets.compile = true
  config.assets.digest = true
  • If you want a different max-age for your static assets, you can override the default:
  config.static_cache_control = "public, max-age=31536000"
  • Optionally, I prefer precompiling assets prior to deploying to Heroku to ensure that assets compile properly (if not, Heroku will enable runtime compilation which will slow your app down tremendously).
  RAILS_ENV=production rake assets:precompile

Contributing to heroku_rails_deflate

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
  • Fork the project.
  • Start a feature/bugfix branch.
  • Commit and push until you are happy with your contribution.
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Thanks

This gem uses a combination of techniques from this gist by guyboltonking and romanbsd's gem heroku-deflater.

Copyright

Copyright (c) 2013 Matt Olson. See LICENSE.txt for further details.

heroku_rails_deflate's People

Contributors

mattolson avatar aitherios avatar xentek avatar

Watchers

Ajmal Afif avatar James Cloos 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.