4 ms·
I recently (2 months ago) started using Cloudfront (on Mugasha.com) for all our static assets. Images, CSS and JS so far, going to move to audio and video asse
by lyime 16y ago
I recently (2 months ago) started using Cloudfront (on Mugasha.com) for all our static assets. Images, CSS and JS so far, going to move to audio and video assets to Cloudfront spill over soon.
Setup is pretty straight forward, it took a few days to get it right. The main problem with Cloudfront and S3 is that it does not GZIP the files for you on fly based on headers (if browser accepts gzip).
So here is the process I have setup for a rails app.
0. Store all the static assets paths in a config file. LIke this http://grab.by/51Zh http://grab.by/51Zh. Then I modify the CSS and JS helpers with something like <%= include_stylesheets :common, :media => 'all' %>
1. Make changes to code (js/css/images)
2. Create a folder on s3 with a unique name based on the commit and time stamp. Store that folder name in some config file.
3. Run a script, that uploads all the images to cloud front. Then does a replace in all the CSS and JS file for image urls that are cloudfront based (asset1-5.mugasha.com for background images etc) Then combine, minify and compress/gzip css and js files. Upload files.
4. Commit and deploy.
Each time I run the script and deploy, the asset urls are automatically generated.
I am not sure if this is useful info, but I wanted to share anyway.
I am using modified version of Jammit http://documentcloud.github.com/jammit/ http://documentcloud.github.com/jammit/
- JangoSteve 16y agoThis is almost exactly the same process I use as well for RateMyStudentRental and LeadNuke, with a few exceptions. -Instead of Jammit, I do this with a plugin + manually written Capistrano deploy script. -Instead of serving CSS and JS (only 2 files since they're combined and cached) from CloudFront pre-zipped, I serve them from my own server, so I can detect the Accepts-encoding header in the incoming request and serve the appropriate file (so as not to leave out the rare request that does not accept gzip encoding). -Instead of creating a new s3 bucket every deploy and having to recopy the entire contents of the assets folder, I simply sync the existing folders, and let Rails take care of the file caches by updating the appended modified-date in the filenames themselves. Anyway, I wrote a how-to post on this just last week if anyone is interested http://www.alfajango.com/blog/caching-zipping-and-cdn-for-a-rails-app/ http://www.alfajango.com/blog/caching-zipping-and-cdn-for-a-...