[Mapbender-dev] Packer (code conventions)

Marc Jansen jansen.marc at gmx.de
Tue Feb 6 10:34:29 EST 2007


Hey Mapbender developers,


Christoph Baudson (WhereGroup) schrieb:
> Hi Marc, hi Paul, hi list,
>
> Paul, JSLint is yet another great tool, thanks for sharing.
>
> Marc, here's what I think about your reply.
>
>> Yes the names are shortened, but that should not be a problem since 
>> everything  done by Dean Edwards packer is being reverted as the 
>> script is loaded. The whole resultung function (p, a, c, k, e, 
>> d){...} is being evaluated at once. Different scripts are sent 
>> through eval in the order of presence of script-tags in the markup. I 
>> used is together with about 6 other scripts and there were no problems.
>
> This is quite interesting. I believed that variable names were just 
> shortened. Where did you get your information from? 

... I did it the inductive way: try and see: ;-)

an example script:

var aVeryLongNameThatWontBeShortened = {
  "first" : 1,
  "second" : 3,
  "aMethodYeah" : function() { alert(this.first); },
  "anotherOne" : function() { alert(typeof this.aMethodYeah); },
  "multi" : {
    "multiOne" : {
      "myArray" [1, 2 , 3 , 4 , 5 , 6 ],
      "anotherArray" ["a", "b", "c"]
    }
    "multiTwo" : {
      "myArray2" [1, 2 , 3 , 4 , 5 , 6 ],
      "anotherArray2" ["a", "b", "c"]
    }
  }
};

Bhen you run this  through the compression script (getting a bigger 
result as the scripts to small), you will get something like this 
[shortened and with linebreaks]:

eval(
  function(p,a,c,k,e,d){e=function(c){return c.toString(36)};  [...] 
'first|||||||aMethodYeah|alert|function||||this|anotherArray|multiTwo|myArray2|anotherOne|typeof|anotherArray2|aVeryLongNameThatWontBeShortened|myArray|multi|multiOne|var|second'.split('|'),0,{}))

do you see the parts at the end? These are just exactly the names I 
chose for my stupid example. Within the function(p,a,c,k,e,d) {} the 
methods, vars ... are referenced by their short names, but in the end 
(after eval has done the job) your can us just what you originally typed in.

But with all inductive research... one can never be sure based on 
n-examples... so perhaps take a look at the source?


> The documentation of Dean Edwards' packer is not the best.

Yes, that's right
>
>> Sure enough other packers should be considered. Can't we make up a 
>> small test page in the wiki with results for some of the tools and 
>> pros and cons for each?
>
> A first draft is up at
>
> http://www.mapbender.org/index.php/For_developers#Packing_JavaScript_code

Good start!

I think Pauls email has summed up everything nicely. And just to 
clearify: JSMIn would be a perfect choice as well.
>
> Any input will be highly appreciated.
>

Just my two cents.

-- Marc


More information about the Mapbender_dev mailing list