Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET using MS bundles and Grunt with a CDN

I'm currently using the built-in BundleConfigs which work great locally and deployed, but I'd like to move all my static assets to a CDN. I know the bundle syntax allows you to specify a CDN path which will work, but does anyone have a good solution to keep the BundleConfigs in sync with your deployment scripts -- which will ultimately handle the concat/minify/copy of your statics to the CDN?

I'm currently looking into Grunt to concat/minify my styles/scrips, but this will cause me to have to manage all my bundles in my solution's BundleConfig.cs, and then again in my Gruntfile.js. Not ideal...

Thoughts or suggestions? Thanks!

like image 674
bmherold Avatar asked Jan 11 '23 07:01

bmherold


1 Answers

If you're going to use Grunt for bundling and minification, then I don't think you need to use ASP.NET Web Optimization framework. Why to use both? Just insert links to your bundled app.css and app.js files on your page and you're all set. You can also use @if ... statements to include different versions of your files (development vs production).

Also, take a look at Gulp.js - a newer alternative to Grunt, and this project template, which already has some basic Gulp.js configuration in place: ASP.NET Solution Template

A couple of Gulp.js plugins which can help with a CDN:

  • gulp-s3 - Uploads your static files to Amazon S3 during a build
  • gulp-google-cdn - Replaces references to 3rd party libraries with Gogole CDN links

After Gulp.js is configured via gulpfile.js file, you can run:

gulp build --production

..in order to build your HTML/LESS/JS files and publish them to Amazon S3 or some other CDN.

like image 179
Konstantin Tarkus Avatar answered Jan 13 '23 21:01

Konstantin Tarkus