magnars / optimus

A Ring middleware for frontend performance optimization.
364 stars 23 forks source link

Uglify removes seemingly unused global vars #5

Closed magnars closed 10 years ago

magnars commented 10 years ago

hmm have you ever encountered js minifier used by optimus to remove vars defined outside functions ?

var appletId;
var appletRef;
var s = "asasasdasd";
function appletReady(){
    alert(s);
    var d = "Ddd";
    alert(d);
    var tokens = "mytokens";
    alert(tokens);
}

Maybe they're optimized away because uglify thinks we're in a node script, and it needs to be told that it's in a browser.

magnars commented 10 years ago

@zilvinasu After some investigation, I see that the're not missing. They're reorganized. It minifies into this:

function appletReady(){alert(s);var a="Ddd";alert(a);var e="mytokens";alert(e)}var appletId,appletRef,s="asasasdasd";

Look at the end of that string. There they are.

zilvinasu commented 10 years ago

Oh sorry for confusing you, thanks!

magnars commented 10 years ago

No worries, mate. :) I'm very glad you're reporting issues, since then I can iron out the wrinkles for the next one in line.