digitalbazaar/bedrock-angular-lazy-compile

Name: bedrock-angular-lazy-compile

Owner: Digital Bazaar, Inc.

Description: Bedrock AngularJS Lazy Compile

Created: 2015-01-20 23:20:24.0

Updated: 2017-09-09 01:40:02.0

Pushed: 2017-11-13 21:48:31.0

Homepage: null

Size: 22

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

bedrock-angular-lazy-compile

An AngularJS module that provides a directive that can be used to delay the compilation of other directives until some specified event occurs. The main purpose of the directive is to improve your application's start up time or time to render.

Quick Examples
directive br-lazy-compile="model.compileWhenTruthy"></my-directive>
tml
 br-lazy-compile="model.compileWhenTruthy">
>Some text</p>
y-wrapped-directive></my-wrapped-directive>
v>
tml
ipt type="text/ng-template" id="demo.html">
-- use br-lazy-id to optimize large content -->
y-directive
br-lazy-compile="model.compileWhenTruthy" br-lazy-id="demo.html">
<div>
  <p>Some text</p>
  <div>Pretend there are a bunch more elements here...</div>
</div>
my-directive>
ript>
Setup
r install bedrock-angular-lazy-compile

If you're using bedrock-angular, installation of the module followed by a restart of your bedrock server is sufficient to make the directive available to your application.

To manually add bedrock-angular-lazy-compile as a dependency:

lar.module('myapp', ['bedrock.lazyCompile']);
How It Works

A br-lazy-compile directive can be used to modify or wrap any HTML elements that may contain directives in order to delay their compilation.

When a br-lazy-compile directive is compiled, it saves a reference to the contents of the directive and then removes it from the DOM. At link time, a one-time binding is established that watches the expression associated with the br-lazy-compile property on the HTML for the directive. Once that expression evaluates to something truthy, the directive will be compiled, which will insert the contents back into the DOM, remove any br-lazy-* properties, recompile the element, and link it with the appropriate scope.

An optional br-lazy-id property may be used to optimize the amount of memory used to store uncompiled contents. If your application uses a br-lazy-compile directive to modify or wrap the same (verbatim) HTML in more than one place (likely with the use of templates), you can avoid double storing the HTML contents by providing a unique ID for that particular HTML via br-lazy-id.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.