steva
asked on
Linking to minimized code
Suppose I have some inline JavaScript:
And changeData() is inside an external common.js file that I load first with
That should work.
But now I decide to minimize common.js so that now changeData() becomes something like A(B,C). And to pick up the minized version I change the <script> tag to
How does the inline call to changeData() now find the minimized version of the function?
Thanks
changeData(mode, data);
And changeData() is inside an external common.js file that I load first with
<script src="js/common.js" type="text/javascript"></script>
That should work.
But now I decide to minimize common.js so that now changeData() becomes something like A(B,C). And to pick up the minized version I change the <script> tag to
<script src="js/common_min.js" type="text/javascript"></script>
How does the inline call to changeData() now find the minimized version of the function?
Thanks
ASKER
Julian,
Leakim,
Your article is about the closure compiler, but my understanding is that browsers interpret JavaScript, so I'm not sure where a compiler fits in.
When you minimize code can you just take just one of, say, four JavaScript files and minimize it alone? It seems that something has to look at all of the JavaScript that's going to turn together and "link" it.
What did you use to minify the code?I'm looking at someone else's existing code, so I don't know what they used.
Did you try running JSLint on the code before hand to ensure there were no issues in the un-minified script?The minimized code runs fine. That's not the problem. I'm just trying to understand how a minimized function gets found by code that calls it by its unminimized name.
Leakim,
Your article is about the closure compiler, but my understanding is that browsers interpret JavaScript, so I'm not sure where a compiler fits in.
When you minimize code can you just take just one of, say, four JavaScript files and minimize it alone? It seems that something has to look at all of the JavaScript that's going to turn together and "link" it.
so I'm not sure where a compiler fits in
it's a compiler because it run the script to << find >> :
- short way to
- best method to
- simplify code
for example :
var a = 0;
a = a + 1;
mimifying don't reduce this code because it don't "evaluate"/compile it
the compiler know it can "reduce" the two successive line by : var a = 1;
this is a simple example but the same one :
var a = 0;
var x = document.getElementById("field");
callFunctionThatDontUse_a();
a = a + 1;
here again the compiler is able to short the codevar a = 1;
var x = document.getElementById("field");
callFunctionThatDontUse_a();
the difference is the compiler evaluate the code, mimifier don'tI think you're going to find your answer in this great google video :
http://www.youtube.com/watch?v=M3uWx-fhjUc
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Hi Leakim,
I went through the Closure video. I wasn't impressed until he got to this slide:0.5%!
I also liked what he said about it being a effective obfuscator. The output code looks
virtually impossible to reverse-engineer.
So I ordered the Closure book from Amazon.
He didn't talk about a UI, though. Are there calls in there to let me drag and drop and sort and put up modal dialog boxes, etc.?
Thanks!
Steve
I went through the Closure video. I wasn't impressed until he got to this slide:0.5%!
I also liked what he said about it being a effective obfuscator. The output code looks
virtually impossible to reverse-engineer.
So I ordered the Closure book from Amazon.
He didn't talk about a UI, though. Are there calls in there to let me drag and drop and sort and put up modal dialog boxes, etc.?
Thanks!
Steve
yes, I don't see any problem with what you code render on the screen
Did you try running JSLint on the code before hand to ensure there were no issues in the un-minified script?
More info here
http://stackoverflow.com/questions/3579183/minified-js-causes-js-to-not-work