-
Notifications
You must be signed in to change notification settings - Fork 15
CSS optimizations
The Aggregator provides a CSS module builder for building/minifying CSS files. The CSS module builder performs the following optimizations on CSS resources (resources who's module names end with .css):
- White-space and comment removal
- Optional execution of configured PostCss plugins (provided that the plugin runs in Rhino).
- Optional inlining of image references using the Data URI Scheme
- Optional inlining of CSS files imported using the
@import
statement
Applications can use the CSS Loader Plug-in to load CSS files using AMD.
Various options and parameters for controlling the behavior of the CSS module builder are specified using properties in the Server-Side AMD config file. The following config properties are recognized by the CSS module builder:
Inlining of image references in CSS can improve web application performance by reducing the number of HTTP requests needed to load the application, but it must be used with care because if mis-used, it can negatively impact performance by bloating the size of the CSS. In particular, image sprites should never be inlined. Image sprites are used to leverage browser caching by allowing multipe images to be loaded and cached with a single HTTP request. Since inlining of image references in CSS reproduces the image data within the CSS each time the image is referenced, it is virtually always better to load image sprites separately than to inline them. The best candidates for inlining are small images that are referenced infrequently. The config properties discussed above are designed to provide enough flexibility in controlling which images will be inlined and which won't so that you can fine-tune the performance of your application. Another consideration when deciding whether or not to make use of image reference inlining is that some older browsers may not fully support inlining of images in CSS files.
Inlining of imported CSS files using the @import
directive is provided mostly for legacy code that uses a monolithic CSS file, importing all the styles for the application (e.g. dijit theme files such as tundra.css). AMD applications are encouraged to specify styles in module specific CSS files that are 'required' by the JavaScript modules for the widgets that reference those styles.