Search code examples
javascriptminify

javascript minification that removes licenses?


Javascript minification will generally remove all comments from source. This means that license information is also removed.

If I run a big site, and I want to abide by licenses, does that mean that I cannot use automatic minification? There is no option to "preserve the first comment, but not the others " right?

I ask because a rather big company has used some code I wrote and not included my (MIT) license, but before I get all peeved, I want to put myself in their shoes.

edit:
It seems that as the author the burden is on me to comment the license in such a way (see answers) that it does not get removed during the minification. I am OK with doing that first, and then raising a stink if my license is still removed


Solution

  • This is a classic case of "it depends".

    It depends on the minifier. For example UglifyJS will leave in the initial comment block in a file unless you specifically tell it not to with the -nc flag. Others (like Google's Closure Compiler) look for a special annotation (e.g., @license or @preserve). Some respect "loud" comments (e.g., /*! ... */) while others don't.

    It depends how you minify. Some organization are aggressively minifying and concatenating everything to squeeze out every byte. Others are adding the licenses in source control and "leaving them in" during minifying. Others are applying license files after everything has been concatenated together.

    It can be easy for some place to drop a license in their production builds, especially if they're aggressively concatenating every library they use into a single JS file. They may not even know that they're doing it. Your best bet here is probably just to reach out and ask them to make sure that they're respecting the terms of the license and leave the license text on there -- they may not even realize that they're doing it.