1

Encoding JavaScript files with base62 diminishes its file size but reduces performance. But how, exactly?

  1. Once the JavaScript file is loaded, does the JavaScript engine have to unencode the file only once or does it have to unencode it in real time, as the script runs?

  2. If the file is unencoded only once, where is it stored?

André Casal
  • 1,012
  • 1
  • 11
  • 25
  • @T.J. Crowder I mean base62, as in http://dean.edwards.name/packer/ Base62 is a positional notation so it can be used to represent very long normal text by a very shorter version. – André Casal Mar 05 '13 at 13:08
  • @ Amoguai: Ah, with you. – T.J. Crowder Mar 05 '13 at 13:15
  • @T.J. Crowder Oh I see. Thank you for clearing that up :) I'm going to run another test. – André Casal Mar 05 '13 at 13:16
  • 1
    @ Amoguai: No, you're right, it definitely makes things smaller given enough to work with. But as Edwards [points out](http://dean.edwards.name/weblog/2007/08/js-compression/), it's only worth doing if you can't use gzip, which you nearly always can. – T.J. Crowder Mar 05 '13 at 13:16
  • @T.J. Crowder Yes I just confirmed that too, running the same 200 line JS file through Dean's packer with and without base62. Base62 encoding resulted in a 30% smaller file size. – André Casal Mar 05 '13 at 13:21

1 Answers1

2

Once the JavaScript file is loaded, does the JavaScript engine have to unencode the file only once or does it have to unencode it in real time, as the script runs?

Every time the script is loaded (so, once per page load).

If the file is unencoded only once, where is it stored?

JavaScript code is executed, not stored, and the result of the execution (which might involve some structures that are stored, such as functions) lives in memory in the JavaScript heap.

As you mentioned Dean Edwards' packer, it's worth pointing out that he makes the point that using the Base62 encoding is only useful if you can't use gzip compression, which one nearly always can. Browser support is essentially universal, as is server support for on-the-fly gzipping (and in good servers, pre-gzipped and cached).

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • Thank you for your quick reply, however, I meant base62, not 64 :) Base62 encoding adds a bit of overhead so it will be bigger for very small files, but for real world JS files the size is tremendously decreased. I just tested it with a 200 line JS file and the reduction was of 60%. – André Casal Mar 05 '13 at 13:13
  • @Amoguai: Yeah, I updated the answer (apparently literally *as* you were commenting). – T.J. Crowder Mar 05 '13 at 13:15