Link to home
Create AccountLog in
Avatar of steva
steva

asked on

Linking to minimized code

Suppose I have some inline JavaScript:

changeData(mode, data);

Open in new window


And changeData() is inside an external common.js file that I load first with

<script src="js/common.js" type="text/javascript"></script>

Open in new window


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>

Open in new window


How does the inline call to changeData() now find the minimized version of the function?

Thanks
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

What did you use to minify the code?

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
Avatar of steva
steva

ASKER

Julian,

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;

Open in new window


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;

Open in new window

here again the compiler is able to short the code
var a = 1;
var x = document.getElementById("field");
callFunctionThatDontUse_a();

Open in new window

the difference is the compiler evaluate the code, mimifier don't

I think you're going to find your answer in this great google video :
http://www.youtube.com/watch?v=M3uWx-fhjUc
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of steva

ASKER

Hi Leakim,

I went through the Closure video.  I wasn't impressed until he got to this slide:User generated image0.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