### JavaScript Optimizer

JavaScript code can be optimized by a JavaScript Optimizer, Closure Compiler, propvided by Google.
The Closure Compiler compiles JavaScript into compact, high-performance code.
The compiler removes dead code and rewrites and minimizes what is left so that it downloads and runs quickly.
It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls.
These checks and optimizations help you write apps that are less buggy and easier to maintain.
Information
• https://developers.google.com/closure/compiler/
• https://developers.google.com/closure/compiler/docs/gettingstarted_app
Compile
java -jar compiler.jar --js myscript.js --js_output_file myscript-compiled.js
Online Help
java -jar compiler.jar --help
Example optimizing jQuery Version 1.11.1 JavaScript code
java -jar compiler.jar --js jquery-1.11.1.js --js_output_file jquery.min-1.11.1.js
Hint:
For this example, jQuery offers also a compressed production version:
http://code.jquery.com/jquery-1.11.1.min.js
Example HelloWorld
JavaScript
// File: helloworld.js
// A simple function.
function hello(longName) {
alert('Hello World, ' + longName);
}
hello('My Name');
Batchfile Compile
java -jar compiler.jar --js helloworld.js --js_output_file helloworld-compiled.js
HTML File using helloworld-compiled.js
<html>
<head><title>Hello World</title></head>
<body>
<script src="helloworld-compiled.js"></script>
</body>
</html>

Changed: , Category: WebApps, File: T6C277M2071.htm, ID: 2071