thoughtbot/suspenders — pull request #228 by croaky (2013-09-22 23:28:25+00:00)
Title: Set up staging and production for Cloudfront CDN

The value of `ASSET_HOST` will look like `//123abc.cloudfront.net

In production every asset has a hash added to its name. Whenever the file
changes, the browser requests the latest version as the hash and therefore
the whole filename changes.

Putting the assets version in an environment variable makes it possible to
invalidate the cache without a re-deploy, if necessary. Simply re-set the
`ASSETS_VERSION` as a Heroku config variable to change the hash globally and
make the browser request every asset again.

Stuff we already have in Suspenders that makes this all work:

Gemfile:

gem 'coffee-rails'
gem 'sass-rails'
gem 'uglifier'

config/environments/{staging,production}.rb:

config.assets.compile = false
config.assets.digest = true
config.assets.js_compressor = :uglifier

We don't have to set `config.serve_static_assets = true` because the
`rails_12factor` gem does it for us.

We want the following settings in Cloudfront:

* "Download" Cloudfront distribution
* "Origin Domain Name" as www.example.com (our app's URL)
* "Origin Protocol Policy" to "Match VIewer"
* "Object Caching" to "Use Origin Cache Headers"
* "Forward Query Strings" to "No (Improves Caching)"
* "Distribution State" to "Enabled"