-
Notifications
You must be signed in to change notification settings - Fork 0
AssetsGoogleClosureCompiler
The Closure Compiler is a tool for making JavaScript download and run faster. It is a true compiler for JavaScript - though instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what’s left.
Any JavaScript file present in app/assets will be parsed by Google Closure compiler, checked for errors and dependencies and minified if activated in the build configuration.
JavaScript code is compiled during the compile command, as well as automatically when modified. Error are shown in the browser just like any other compilation error.

Play’s Closure Compiler integration can also resolve dependencies that you declare with a CommonJS style, similarly to RequireJS.
Consider the lib.js file:
// The lib
function sum(a, b) {
return a + b;
}
exports.sum = sum;
And the test.js file:
// The test
require("lib");
function showSum(first, second) {
alert(require.modules.lib.exports.sum(first, second));
}
showSum([2,3], 4);
After compilation, the file served for test.js will be the following:
require.register("lib", function(module, exports, require){
// The lib
function sum(a, b) {
return a + b;
}
exports.sum = sum;
}
require("lib")
// The test
function showSum(first, second) {
alert(require.modules.lib.exports.sum(first, second));
}
showSum([2,3], 4);
A minified file is also generated, where .js is replaces by .min.js. In our example, it would be test.min.js.
- Working with public assets
- Using CoffeeScript
- Using LESS CSS
- Using Google Closure Compiler
- Using RequireJs
- Installing Play
- Creating a new application
- Anatomy of a Play application
- Using the Play console
- Setting-up your preferred IDE
- Sample applications