Two quick tips to speed up Rails 3 on Heroku
There are lots of ways to speed up your Rails site, but here are two I see a lot of sites neglecting: gzipping and serving jQuery by CDN.
Enabling gzip on Heroku
Heroku’s Cedar Stack by default doesn’t gzip assets, which means everything is sent to the browser uncompressed. This goes against best practices, and can slow down your load times considerably. Luckily it’s a super easy fix. In your config.ru
, just use Rack::Deflater
before you run your application:
require ::File.expand_path('../config/environment', __FILE__)
use Rack::Deflater
run MyApp::Application
Technically, we’re using DEFLATE
rather than GZIP
- there’s a good write-up of the subtle differences here.
Loading jQuery from a CDN
By default Rails 3 uses jQuery, and by default it serves jQuery through your app’s asset pipeline. This probably isn’t ideal - loading jQuery from a content delivery network (CDN) can speed things up significantly, Dave Ward has a great write-up of why that is. Again, it’s really simple to set up, thanks to the jquery-rails-cdn gem.
Full instructions are on Github, but basically you need to remove:
//= require jquery
from your application.js
, and in your layout add:
= jquery_include_tag :google
I’d recommend sticking with Google’s CDN, but there are other options to choose from. Pingdom has a very thorough rundown of the pros/cons of the various CDNs out there.
Loading comments...