-
Notifications
You must be signed in to change notification settings - Fork 15
Home
The purpose of this wiki is to provide useful information about the JavaScript Aggregator project. The JavaScript Aggregator (or, throughout this wiki, the Aggregator) is an OSGi servlet that provides aggregation and code minification services to an AMD loader that supports the loader extension API. At the time of this writing, the Dojo loader in Dojo 1.7.3 and greater supports this API, and Dojo 1.7.1 or 1.7.2 may be used with this patch http://bugs.dojotoolkit.org/ticket/14198.
AMD stands for Asynchronous Module Definition. The AMD API specifies a mechanism for defining modules such that the module and its dependencies can be asynchronously loaded. Organizing JavaScript code into modules aids development by promoting modularization and code reuse, but can result in an excessive number of requests, impacting the performance of web applications.
There are two general approaches to resolving this problem:
- Static layer builds - collections of minified and aggregated modules organized into pre-defined layers that are defined by developers
- On-demand module aggregation and minification performed by some server-side process
The JavaScript Aggregator is an instance of the later approach. It utilizes a client-side component that hooks into extensions provided by an AMD loader in order to collect and combine requests for multiple modules into a single HTTP request/response. In addition to module aggregation, the Aggregator also provides:
- JavaScript minification using the Google Closure compiler with support for source maps
- Code trimming using has.js feature detection
- Resource Aggregation with dependency expansion to reduce the cascade of requests resulting from dependency discovery as modules are loaded on the client
- A CSS loader plugin that allows LESS/CSS modules to be loaded using AMD
- LESS Compilation
- CSS Optimizations with support for PostCSS plugins
- JSX to JavaScript conversion
- i18n resource consolidation
- Caching of previously built/minified output for quicker response on subsequent requests with a cache-primer feature allowing the Aggregator cache to be populated prior to deployment.
##Extensibility
The Aggregator supports extensibility through the eclipse extension registry which is supported by the OSGi framework. Four extension points are provided. They are:
- com.ibm.jaggr.service.resourcefactory - Provides the ability for third-parties to support resources in alternate repositories such as jar files, databases, etc. By default, the Aggregator supports resources on the server's file system and in OSGi bundles.
- com.ibm.jaggr.service.modulebuilder - Provides the ability for third-parties to support build/minification of resource types specified by file extension (e.g. css, html, etc.). The Aggregator provides default implementations for the javascript and css builders.
- com.ibm.jaggr.service.resourceconverter - Provides the ability for third-parties to support conversion of resources from one source content type to another. The JSX resource converter implements this extension point.
- com.ibm.jaggr.service.httptransport - Enables third parties to provide named HTTP transport implementations. The HTTP transport is the component responsible for extending the client loader, forming the HTTP requests to the server and on the server, for parsing and interpreting the request. The HTTP transport also deals with any loader specific output requirements, such as formatting of the response, etc.
- com.ibm.jaggr.service.serviceprovider - Provides the ability for third-parties to extend the aggregator by registering OSGi services used by the Aggregator. Such services include com.ibm.jaggr.core.IVariableResolver, com.ibm.jaggr.core.options.IOptionsListener and com.ibm.jaggr.core.config.IConigScopeModifier, etc.
A major design goal for the project is that it's use is transparent to the application. This means that the Aggregator does not impose any coding requirements or provide any API for use by the client application (other than requiring a loader config property). If your application is written to use an AMD loader, and that loader supports the loader extension API, then you may start using the Aggregator by providing a bit of config information and loading the script that contains the loader extension code. And you can easily switch between using, or not using, the Aggregator simply by choosing whether or not to load the loader extension code.
Binaries may be downloaded from the project page on OpenNTF
- FAQs
- Features
- Using the Aggregator
- Development
- Specification