Search code examples
javascriptperformancebase62

JavaScript base62 encode performance implications


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?


Solution

  • 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).