Preserving Important Comments in Bundling and Minification

I recently read an interesting question on Stack Overflow - How can I preserve comments that matter in MVC 4 style bundling?

Good point. All comments, event ones marked as "important" /*! like some important licensing info */ by default, get stripped out.

So then I went to the jQuery site and read this:

You are free to use any jQuery project in any other project (even commercial projects) as long as the copyright header is left intact.

Oh. You mean the copyright header that ASP.NET Bundling and Minification just stripped out.

So, I made a NuGet Package that is an add-on to the Microsoft ASP.NET Web Optimization Framework bundling and minification that will keep important comments in your bundles. I like this package for a few reasons.

  1. It keeps you in compliance using other peoples' scripts
  2. It allows you to keep your own licensing info intact
  3. When a particular file fails to properly minify, the error messages and the offending file get placed at the top of the bundle, but all other files are minified (the default functionality in bundling is that on error, no files in the bundle are minified)
  4. It keeps regular comments hidden from prying eyes who switch user agent, as specified in Changing User-Agent to Eureka/1 Changes Output in ASP.NET Bundling and Minification

It's easy to use. Just install the NuGet Package by running the following command in the Package Manager Console:

PM> Install-Package LicensedBundler

And then simply use LicensedScriptBundle or LicensedStyleBundle in place of ScriptBundle and StyleBundle in your BundleConfig.cs to preserve important comments in bundled and minified files.

Contribute to the project!

It's on Githhub at