1

I'm using multiple third party javascript libraries in my website, and right now I'm keeping each third party library as a separate .js file, with its own <script> tag.

But I would like to use the Closure Compiler with Advanced Optimizations. This requires that I either concatenate all the javascript in my website together or make a lot of modifications to my code. Obviously, I would prefer to simply concatenate all the javascript together then run it through Closure Compiler, but then where would I put the licenses and attribution for this code?

Not only that, but the actual 3rd party code will be modified as it runs through the Compiler.

All the third party libraries either use MIT, BSD, or CC0 1.0 Universal.

1 Answer 1

0

You may indicate to Closure Compiler to preserve copyright/license info by using @license syntax, as shown in the documentation:

/**
* @preserve Copyright 2009 SomeThirdParty.
* Here is the full license text and copyright
* notice for this file. Note that the notice can span several
* lines and is only terminated by the closing star and slash:
*/

As for the third-party code being modified by Closure Compiler, you have a choice:

  • Keep this third-party code as-is in a separate file, and use the feature explained in Solution for Calling out from Compiled Code to External Code: Externs.

    For popular libraries, I highly recommend you this alternative; especially, being able to use a popular CDN such as Google's one (for example for JQuery) will only reduce the bandwidth to your servers and make your application faster, since some users may already have the CDN's file cached by their browsers before even visiting your site for the first time.

  • Contact the authors of the third-party code to ask them if they are interested in producing code which compiles correctly with Closure Compiler.

  • Modify the code yourself (and don't forget to submit your changes if the project is open sourced).

Note that passing third party libraries through Closure Compiler doesn't necessarily provide a benefit over the original version. The question jQuery compiled with Google Closure Compiler provides an interesting discussion about the benefits and drawbacks of such approach (one should note that the question was written in 2009, so the information is not accurate any longer).

5
  • So is what you're saying, there is no legal way to simply concatenate a third-party library with my code and run it through Closure? (as opposed to using Closure's Externs) Jul 27, 2014 at 22:12
  • There is a way to do it: use @preserve. Jul 27, 2014 at 22:14
  • So would I just put all 6 or so licenses at the top of my compiled code? My only concern is that after running a large concatenated js file through Closure, it is difficult to tell where any particular piece of code originated from. Jul 27, 2014 at 22:17
  • You keep the licenses where they are in the original code. Then, you concatenate them, meaning that you'll end up with license 1, code 1, license 2, code 2, ... license n, code n, your own code. Jul 27, 2014 at 22:30
  • Thank you very much. I don't know why I couldn't come up with that myself :P Jul 27, 2014 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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