Is it bad to Base62 encode a javascript file?

后端 未结 2 387
清酒与你
清酒与你 2020-12-28 16:13

I just found Dean Edwards javascript packer here: http://dean.edwards.name/packer/

It has a couple of options,

  1. Base62 encode
  2. Shrink variable
相关标签:
2条回答
  • 2020-12-28 16:54

    It does create more work on the client. The client has to run the code to decode the encoded script. This is pretty obvious if you enter just a little bit of code in the encoding block.

    For example:

    var a = 10;
    

    Encodes as:

    eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('0 1=2;',3,3,'var|a|10'.split('|'),0,{}))
    
    0 讨论(0)
  • 2020-12-28 17:12

    Base 62 is nothing but a positional notation. That is, it can be used to represent very long normal text by a very shorter version.

    Using Base62 adds an extra step before the js can be put to use by clients. For jQuery kind of library this step may take an extra 100ms to 500ms of time on clients, depending on many factors.

    Now we can compare the reduction in time to download the script to extra time taken to execute the script. It may reduce download time by 50ms but takes an extra 100ms to process it. Diminishing returns!!

    0 讨论(0)
提交回复
热议问题