I’m optimizing my ASP.net MVC 4 website. I’m currently using run time bundling to combine and minify my JavaScript and CSS content. I would like automate publishing of the minified content to a CDN (specifically Amazon Cloudfront) as they are created.
I am trying to determine the best strategy for integrating bundled files with a CDN. My specific questions are:
- Are there any available libraries that would allow bundled files to
be saved to a CDN rather than my local web server? - Should static files be pulled from a CDN prior to bundling or should they be pulled from a local Web server prior to bundling?
- Are there any mechanisms to enable CDN write control only from my web farm (and not the general public)?
After more research I came across the Squishit.S3 library which does exactly what I needed. Essentially it piggy-backs on squishit, enabling bundled files to be copied to an S3/Cloudfront bucket at runtime. Configuration is a breeze and because it uses Amazon’s APIs, credentials are used to write to the CDN. If you already use Squishit it’s just a matter of adding a couple of default configuration lines to your global.asax and the rest is taken care of for you