Skip to end of metadata
Go to start of metadata
You are viewing an old version of this page. View the current version. Compare with Current  |   View Page History

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

Zend Framework: Zend_Dojo Automated Build Layers Component Proposal

Proposed Component Name Zend_Dojo Automated Build Layers
Developer Notes Automated Build Layers
Proposers Matthew Weier O'Phinney
Zend Liaison TBD
Revision 0.1 - 13 January 2009: Initial Draft. (wiki revision: 3)

Table of Contents

1. Overview

Dojo is a highly modular Javascript framework with a structure that largely mirrors the 1-class-1-file structure of Zend Framework and PEAR. During development, this is an incredibly powerful paradigm as it provides the flexibility to add new functionality as needed. However, once in production, it can be a liability: each class loaded through dojo.require requires at least one, and in many cases dozens, of additional requests to the server to load dependencies. Fortunately, Dojo has a solution for this via custom builds.

Creating custom builds is relatively trivial. However, at this time, it requires the developer to examine each page, aggregate the dojo.require and other statements, create a layer file, and create the build profile.

Zend_Dojo provides a common point of aggregation for all these areas, and could be repurposed trivially to build a custom layer file and related build profile, which would leave creating the actual build as the only step necessary by the developer. This proposal aims to address this idea.

2. References

3. Component Requirements, Constraints, and Acceptance Criteria

  • This component MUST add the ability to create Dojo custom layer files:
    • Layer files locations COULD be auto-discovered based on the path to dojo.js and the layer name
    • If a CDN is being used, layer files MUST NOT be created
    • The component MUST allow specifying the exact filesystem location to the file; if so, it MUST also require specifying the location relative to dojo.js
    • The generated layer file MUST determine the dependent namespaces from the dojo.require statements
    • Automated build layers WILL be loaded via a dojo.require() statement
    • Any dojo.require statements aggregated by the helper MUST be omitted when the dojo() view helper is rendered
  • The helper should check to see if a layer file already exists; if so:
    • The helper MUST parse the existing layer file, and break it into discrete tokens (dojo.require statements and layer-related javascript)
    • The helper MUST check to see if new dojo.require statements and/or javascript have been registered; if so, it MUST update the layer file.
    • The helper MUST have a flag indicating whether or not live updating of the layer file should occur.
  • When an automated build layer is specified, the component SHOULD allow specifying whether all JS directives should be included in the layer file, or only the dojo.require statements
  • The component SHOULD allow creating the build profile
    • The component SHOULD allow specifying where to write the build profile

4. Dependencies on Other Framework Components

  • Zend_Dojo_View_Helper_Dojo
  • Zend_Dojo_View_Helper_Dojo_Container

5. Theory of Operation

When configuring the dojo() view helper, you will be able to optionally specify an automated build layer. When doing so, you will be able to specify a variety of options:

  • The layer namespace (e.g., "custom", "bug", "contact")
  • The filesystem path to the layer (e.g., APPLICATION_PATH . '/../public/js/custom'); by default, this will be auto-discovered based on the path to dojo.js and the public directory (assumed to be APPLICATION_PATH . '/../public').
  • The path to the layer, relative to dojo.js (e.g., '../custom'); by default, this will be assumed to be the '../$layerNamespace'.
  • The path to the build profile (e.g., APPLICATION_PATH . "/../misc/$layerNamespace.profile.js"); by default, this will be auto-discovered based on the path to dojo.js, and will be in ../util/buildscripts/profiles/$layerNamespace.profile.js.
  • Flag indicating whether only dojo.require statements should be part of the layer, or if all javascript captured by the dojo() view helper should be included. By default, only the dojo.require statements will be included.
  • Flag indicating whether or not the helper should update an existing layer file.

Once you have, anytime a page is hit where the dojo() view helper is rendered, the layer file will either be created or updated, and a corresponding build profile will as well. It is then up to the developer to either manually generate the build from the build profile, or create an automated task for doing so.

6. Milestones / Tasks

  • Milestone 1: Creation of proposal
  • Milestone 2: Working prototype created targetting all MUST and WILL requirements, including unit tests
  • Milestone 3: Updated prototype supporting all SHOULD and COULD requirements, including unit tests
  • Milestone 4: Full documentation of new functionality
  • Milestone 5: Review for inclusion in trunk

7. Class Index

  • Zend_Dojo_View_Helper_Dojo_Layer
  • Zend_Dojo_View_Helper_Dojo_BuildProfile
  • Zend_Dojo_View_Helper_Dojo_Container (updates)

8. Use Cases


Fully automated build layer

The example below creates a fully automated build layer in ../custom/main.js (relative to dojo.js). As the developer browses to pages that utilize different Dojo functionality, it will be updated. Additionally, it will create a build profile in ../util/buildscripts/profiles/custom.profile.js.


Aggregate javascript in the build layer

The example below builds on UC-01, and sets a flag telling the dojo() view helper to aggregate javascript to the build layer.


Only create the build layer file once

The next example builds on the previous, and sets a flag indicating that the build layer file should only be created once, and never updated.


Manually specify where to place the build layer file


Manually specify where to put the build profile file

9. Class Skeletons



Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.