Shaker

Mojito Documentation   ::   Shaker   ::   Getting started   ::   Usage

Shaker Components

Shaker is comprised of three components that work together in various ways depending on the environment. Note that this chapter doesn’t cover any tecnical aspect and is just an overview of the Shaker architecture.

Shaker Core

_images/shaker_core.png

Shaker Core is the foundation of Shaker. It alone has the ability to parse shaker.json configuration files, compute and resolve rollup dimensions and dependencies, and ultimately generate rollup metadata.

Shaker Compiler

_images/shaker_compiler.png

The Shaker compiler is the build time component of Shaker. It employs Shaker Core to generate the metadata and uses it to create the rollups for the application.

Shaker compiler can be configured per environment (staging, test, production) through application.json and you can also decide what actions to apply to the rollups (minify, js/csslint, etc). Moreover, you can set what we call “deployment tasks” which allow developers to deploy rollups to different places:

  • raw - Deploy the assets without doing rollups. This mode will pick the files directly from disk (handy for development).
  • local - Compile rollups and output files locally.
  • s3 - Compile rollups and upload them to Amazon S3 CDN.

Shaker Addon and ShakerHTMLFrame

_images/shaker_addon.png

The Shaker Mojito addon is the runtime component of Shaker. It reads the metadata generated by the Shaker compiler, and subsequently manages assets within the application, picking the correct rollup based on the current environment.

The ShakerHTMLFrame is a copy of the Mojito HTMLFrame, but it additionally includes the addon and executes Shaker automatically.

Putting The Pieces Together

This is how all the components work together:

Build time:

  1. The shaker command gets executed, invoking the Shaker compiler.
  2. ShakerCompiler gets the application configuration and calls ShakerCore.
  3. Shaker core analyzes all the application resources, and returns a metadata object with all the information necessary to create the rollups.
  4. ShakerCompiler takes the previously generated metadata, generates the minified precomputed rollups, and outputs them as files or to CDN.
  5. ShakerCompiler outputs a new metadata file which will be picked up at runtime for picking the correct rollup per context.

Runtime:

  1. The Mojito server automatically picks the generated metadata file.
  2. When a request arrives, Mojito computes everything normally until it reaches the ShakerHTMLFrame. Then the Shaker runtime addon gets executed.
  3. The ShakerAddon checks the current context and the executed Mojits, and picks from the metadata the proper rollup to include into the page, overriding the necessary default mojito assets.
  4. If the client side gets deployed, Shaker also deploys itself to the client to serve future mojit calls.