Reputation: 3022
Is there any javascript minifier out there (online one) which allows defining a namespace? I mean all these minifiers generates code with short variable names like a,b,c ... which may cause conflicts with other minified javascript.
Upvotes: 0
Views: 952
Reputation: 1319
Most (good) minifiers leave globally scoped variables alone since those are the namespace we're in by default. mikeycgto was suggesting that you make sure you keep those down to a minimum:
var page = ( function(){
var scopedVar = "I'm something like private.";
//do some other stuff
return {
usefulThing: function(){
return scopedVar;
}
};
}() );
Running that through a minifier should leave you with a "page" var in the global scope. page.usefulThing is a method (which should also be left alone by the minifier). "scopedVar" may be turned into "a" or "o" or somesuch, but you'll never care. Your API will remain as expected though the internals will be mucked about with.
Upvotes: 3