CDN Fu is a fun domain specific language written in ruby for deployment of assets to content deliver networks. There are 4 pluggable steps in the chain:
There are a lot of ad hoc scripts and rake tasks out there that accomplish these steps, but the idea behind this is to put all the tips and tricks under the same roof in an extensible framework, so that many CDNs and minification strategies can be easily supported.
$ gem install --source=http://gemcutter.org cdn_fu
First install the gem, then do the following
$ cd your_rails_dir $ cdnfu --rails . $ rake cdn:init
This will make cdn_fu.rb in config/ which you can use to configure CDN Fu.
In this example, we want to do the following: use Sass to generate our css files, minify the resulting css as well as our js files using YUI, then upload the minified css, js, and images to an S3 bucket, so they can be used on Cloudfront. It assumes you have a YUI jar file in /usr/bin, but that location is configurable.
Next you want to ensure that your
asset_host are good to
go by adding the following snippet into your production.rb
CloudfrontUploader requires an asset_id to be specified because of how
Cloudfront does its versioning. It takes up to 24 hours for an asset to be
invalidated, so in order to ensure serving of fresh assets, it is good to
RAILS_ASSET_ID whenever you change any of your js/css/image files.
$ rake cdn:upload
and then do a deploy (via capistrano or however you deploy), and your latest assets should be served from Cloudfront
Please let me know if you give this a try. Please file tickets over at github, or find me on Freenode as @jubos (sometimes lounging around #c or #ruby).
You can follow me on Twitter here.