I'm moving ASP.NET bundling into a site I have and I noticed that it is removing all comments from the code including copyright header comments (in CSS and JavaScript). This would be ok if it was my copyrights as I could just create my own IBundleTransform
and add my copyright to the top, but it is not ideal to do this with third party copyrights.
Are there any good ways to keep these copyright headers (or maybe a flag that I haven't fround in the MSDN documentation)? Thanks!
The original answer (see below) is still valid; however, JavaScript has changed a lot since 2013. This rapid change is even compounded by the fact that ASP.NET 5 doesn't even have Bundling in it anymore.
My current solution is to use a JavaScript tool to do the bundling and minification for me. Things like Uglify have options to minify while keeping important header comments. You can combine this with a tool like Gulp, Grunt, etc to trigger this process on build, project loading, or even on demand. This can be accomplished with the Visual Studio window called "Task Runner Explorer", which is built into Visual Studio 2015 and is available as a Visual Studio 2013 extension.
Using a JavaScript tool for minification doesn't fix the issue with cache busting that Bundling solved. There are JavaScript tools to fix this (i.e. gulp-rev), but I don't like the way that they work with ASP.NET. One way of doing this while maintaining a high cache age for static content is to use some sort of hash or fingerprint in the URL. Microsoft employee Mads Kristensen wrote a post about how one might do this caching busting in ASP.NET on his personal blog.
In addition, HTTP/2 and if you are making a site forward facing you will not want/need to combine scripts in bundles like we used to.
As a follow up, the solution I used was to use Bundle
instead of ScriptBundle
or StyleBundle
and just sticking all third party libraries (already minified anyways) into one bundle.
I was about to use @Robert Havey's excellent answer for Bundle Transformer when I realized I could get by without the minification and make a bundle with all third party JS or CSS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With