Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 257
user478249 Avatar asked Aug 04 '11 18:08

user478249


People also ask

Is JavaScript pre compiled?

The source code is passed through a program called a compiler, which translates it into bytecode that the machine understands and can execute. In contrast, JavaScript has no compilation step. Instead, an interpreter in the browser reads over the JavaScript code, interprets each line, and runs it.

What does a JavaScript library do?

Generally speaking, JavaScript libraries are collections of prewritten code snippets that can be used and reused to perform common JavaScript functions. A particular JavaScript library code can be plugged into the rest of your project's code on an as-needed basis.

What is a compiled js file?

The compiled JavaScript files are smaller than your original JavaScript files, reducing download times for your website's visitors. You can also use comments and white space in your original JavaScript code without increasing the file size of the resulting JavaScript files.

What is compiled CSS and JS?

Compiled is a CSS-in-JS library created by Atlassian Labs that aims to provide that excellent developer experience without the runtime cost. It works by statically analyzing your code at build time, transforming it into Compiled components, and then moving the styling code into the head of the document at runtime.


1 Answers

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.

like image 155
700 Software Avatar answered Sep 17 '22 02:09

700 Software