Optimizations
Upgrading to 2.0
- Please make sure you are using the
onModuleBundleComplete
Require.js hook and NOT theonBuildWrite
Require.js hook. TheonBuildWrite
hook has been deprecated for AMDclean versions>= 2.0
. - The
globalObject
andglobalObjectName
options have been removed, since all modules are now hoisted to the top of a file.
Optimizations
AMDclean now uses a few different strategies to decrease file size:
Remove Unused Dependencies
AMD
define('example', ['example1', 'example2'], function() {
var test = true;
});
Standard
// Since no callback parameters were provided in the AMD code,
// the 'example1' and 'example2' parameters were removed
var example;
example = function() {
var test = true;
}();
Remove Exact Matching Dependencies
AMD
define('example', ['example1', 'example2'], function(example1, anotherExample) {
var test = true;
});
Standard
// Since the `example1` callback function parameter exactly matched
// the name of the `example1 dependency, it's parameters were removed
var example;
example = function(anotherExample) {
var test = true;
}(example2);
Hoist Common Non-Matching Dependencies
- Note - For this behavior, you must set the
aggressiveOptimizations
option totrue
AMD
define('example', ['example1'], function(firstExample) {
var test = true;
});
define('anotherExample', ['example1'], function(firstExample) {
var test = true;
});
Standard
// Since the `firstExample` callback function parameter was used more
// than once between modules, it was hoisted up and reused
var example, firstExample;
firstExample = example1;
example = function() {
var test = true;
};
anotherExample = function() {
var test = true;
};