Easy deployment of your assets on CloudFront or S3. When enabled in production, your assets will be served from CloudFront/S3 which will result in a speedier front-end.
Hosting your assets on CloudFront ensures minimum latency for all your visitors. But deploying your assets requires some additional management that this gem provides.
The best way to expire your assets on CloudFront is to upload the asset to a new unique url. The gem will calculate the MD5-hash of the asset and incorporate that into the URL.
By using the MD5-hash we can easily determined which assets aren't uploaded yet. This speeds up the deployment considerably.
gem install cloudfront_asset_host
Include the gem in your app's
The gem relies on
openssl md5 and
gzip utilities. Make sure they are available locally and on your servers.
Make sure your s3-credentials are stored in config/s3.yml like this:
access_key_id: 'access_key' secret_access_key: 'secret'
Create an initializer to configure the plugin config/initializers/cloudfrontasset_host.rb_
CloudfrontAssetHost::Uploader.upload!(:verbose => true, :dryrun => false) before your deployment. Put it for example in your Rakefile or capistrano-recipe. Verbose output will include information about which keys are being uploaded. Enabling dryrun will skip the actual upload if you're just interested to see what will be uploaded.
If the plugin is enabled. Rails' internal
asset_id functionality will be overridden to point to the location of the assets on Cloudfront.
When using in combination with SASS and/or asset_packager it is recommended to generate the css-files and package your assets before uploading them to Cloudfront. For example, call
Feel free to fork the project and send pull-requests.
- Does not delete old assets
Tested on Rails 2.3.5 with SASS and AssetPackager plugins
Created at Wakoopa
Copyright (c) 2010 Menno van der Sman, released under the MIT license