开发者

What is a JavaScript pre-compiled library?

I'm learning how to use Magento e-commerce system, and I'm reading i开发者_如何转开发ts 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


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.


Magento has an configuration option in the admin at

System -> Configuration -> Developer -> JavaScript Settings

named Merged Javascript Files.

When this setting is on, Magento will take all the javascript files it knows about, "compile" them to a minified version to product smaller files sizes, and then combine all the javascript files into a single javascript file. This way, instead of opening multiple network connections to download multiple files, Magento will open a single network connection to open one file.

So, when the documentation says that folder contains the pre-compiled versions, it means that's where the individual javascript files are stored, and where the files are loaded from when Merged Javascript Files

The term compilation comes from Computer Science. A compiler takes source code, and transforms it from one language into another language.

Traditionally, it's meant taking code from a higher level language (C, .NET, Java, etc.), and transforming it into the machine code (assembly code) that's understood by the computer chip. However, the term is generic and more modern usage includes taking the source code written in one language (Javascript) and transforms it into a different form (minified javascript).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜