Search code examples
javascriptmagentoprecompiled

What is a JavaScript pre-compiled library?


I'm learning how to use Magento e-commerce system, and I'm reading its documentation, but I don't understand some term, a "pre-compiled JavaScript library". What do they mean by that? How can JavaScript code be compiled?

The web downloader for upgrading and installing Magento without the use of SSH (covered in Chapter 2). • js—The core folder where all JavaScript code included with the installation of Magento is kept. We will find all pre-compiled libraries of JavaScript here.

Source: http://www.magentocommerce.com/wiki/2_-_magento_concepts_and_architecture/magento_s_base_structure


Solution

  • I do not know what Magento e-commerce uses, but I know what JavaScript Compilers are.

    Pre-Compiled JavaScript is not practical as the various JavaScript interpreters will have their own method of compiling. Therefore, when most people talk about Compiling JavaScript, they are usually referring Minified JavaScript.

    However, the latest minifiers go way beyond. A good example is Google Closure Compiler Advanced Mode. It is related to Google Closure Library and Tools, but is well designed even when used by itself.

    There is an Online Demo of Closure Compiler.

    It is called a Compiler because it is more than a minifier and the name JavaScript Compiler is not used for anything else. For example: This code

    function hello(name) {
      alert('Hello, ' + name);
    }
    hello('New user');
    

    compiles to alert("Hello, New user"); in advanced mode. Single-use functions are removed, variable names are shortened, and even re-used.

    It is very thorough. Simple mode assumes that there might be other JavaScript involved. in which case it would preserve the hello function. Advanced mode assumes that there is only a single JavaScript file, or that it is properly exported.

    The one thing that keeps this from really being compiled is that it is not bytecode like compiled C or Java would be. It still has to be compiled at run-time like Perl.