2

For example, I have a index.js file (copyrighted), I minify it using UglifyJS and store in index.min.js file, but my copyright notice is removed, should I add it again in index.min.js? If yes, Can I automate it? If yes, How can I automate it?

0
4

If the file is entirely your own work, without dependencies that aren't public domain, it's technically not required to preserve anything in the minified version. However, keeping a copyright notice in won't hurt anything, and is probably a good idea.

If the file contains work from others, you are bound by whatever license you received that work under. This will almost certainly include a copyright notice or other form of attribution. amon's answer explains how this can be done with UglifyJS specifically.

You should note that some licenses such as the GNU GPL family distinguish between distributing the source code for a work and other forms of a work. For example, the GPLv3 defines "source code" for a work as "the preferred form of the work for making modifications to it."

Minified JavaScript is certainly not the "preferred form for making modifications". As such, if you yourself are distributing a minified version of software under this sort of license, you may have obligations beyond mere attribution to handle. Without knowing what exactly you're doing it's hard for me to say what these obligations are, but they usually involve making the source code available to recipients.

0
4

Yes, you should keep copyright and license notices in minified files as well. In case you haven't written the code entirely by yourself but have also included code under open source licenses (like MIT or BSD), you are legally required to preserve such notices. As an alternative to keeping the notices within the files, you could also have a separate page that contains open source license notices and attributions – but it would still be good to have a link to the attribution page within the JS file itself.

Per the UglifyJS documentation, it will preserve comments that contain a @license or @preserve annotation. Alternatively, you can pass a regex to the --comments command line option to identify comments that should be retained in the output.

It may also be good to think about why you minify your JavaScript.

  • To obfuscate code? Stripping out comments could be sensible, but aside from that minification doesn't prevent anyone from un-minifying the code and reading it. If the code is open source anyway, this doesn't matter.

  • To reduce bandwidth? Minification is good as a first pass for compression. However, it doesn't replace actual compression algorithms. So keeping a license header is unlikely to produce noticeable overhead, especially if you bundle imports into a single minified file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.