Reputation: 352
I've recently found the Google closure compiler, and it seems very good at what it does.
That being said I'm running into issues when using multiple external code files at once. In my html file I might for example have two different javascript codes embedded:
<script src="code1.js"></script>
<script src="code2.js"></script>
Now I can use the Closure compiler easily to compile and compress both of these scripts individually with advanced optimization, but there might (and most likely will) be issues by both of these scripts overwriting each other/functions being overwritten.
From my own research (reading all the guides on developers.google.com/closure/compiler), there seem to be three solutions to this:
Issue here is that I can't do this, because one part of this javascript code is specific to this html file, while the other part is used elsewhere as well.
Unless there is some way that does this automatically this is too much manual work in my case to make it feasible.
This is what I am currently doing, but obviously if there was a (realistic) way to use the more advanced optimizations, I would prefer using those.
To clarify, the two scripts do not reference each other, the only reason manually optimizing both individually doesn't work is because closure compiler might name a function a(b,c)
in the first script and then another function in the second script a()
as well, thus overwriting the references and functions of the first.
If there was some way
Upvotes: 0
Views: 319
Reputation: 5468
--isolation_mode=IIFE
is recommended. This wraps the entire output of the compiler in a "immediately invoked function expression" (IIFE) which isolates all the global symbols not explicitly set on the global object within the IFFE and will prevent the conflict you are describing.
Upvotes: 0