Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/shekhei/dust-scriptjs-helper

scriptjs helpers for dustjs
https://github.com/shekhei/dust-scriptjs-helper

Last synced: 1 day ago
JSON representation

scriptjs helpers for dustjs

Awesome Lists containing this project

README

        

# A set of helpers for using [script.js](http://github.com/ded/script.js) as async dependency loader with [dust.js](http://github.com/linkedin/dustjs)

## What does it do?

Basically it helps you build your script.js code, and if any depended bundle is not requested, it will not be built. It builds a very simple graph internally and is used to build the code

### Not loading of unnecessary bundles

The following code is very much similar to the above code, except, the final set of script only depends on bundle("two") and as you can see the final result is much shorter(since bundle three is not loaded, bundle one is not needed)

```html

{@bundleScript bundle="one" src="one.js"/}
{@bundleScript bundle="two" src="two.js"/}
{@bundleScript bundle="three" src="three.js"/}
{@bundleDepends bundle="three"}
{@dependsOn bundle="one"/}
{@dependsOn bundle="two"/}
{/bundleDepends}
{@scriptjs}
{@dependsOn bundle="two"/}
{/scriptjs}

{@renderScript /}

$script(["two.js"],"two");
$script.ready("two",function(){
});

{@bundleScript bundle="one" src="one.js"/}
{@bundleScript bundle="two" src="two.js"/}
{@bundleScript bundle="three" src="three.js"/}
{@bundleDepends bundle="three"}
{@dependsOn bundle="one"/}
{@dependsOn bundle="two"/}
{/bundleDepends}
{@scriptjs}
{@dependsOn bundle="three"/}
{/scriptjs}
{@scriptjs dependsOn="one"/}
{/scriptjs}

{@renderScript /}

$script(["one.js"],"one");
$script(["two.js"],"two");
$script.ready(["one","two"],function(){
$script(["three.js"],"three");
});
$script.ready("three", function(){
})
$script.ready("one", function(){
})

{@bundleScript bundle="one" src="one.js"/}
{@bundleScript bundle="two" src="two.js"/}
{@bundleScript bundle="three" src="three.js"/}
{@bundleDepends bundle="three"}
{@dependsOn bundle="one"/}
{@dependsOn bundle="two"/}
{/bundleDepends}
{@scriptjs}
{@dependsOn bundle="two"/}
{@dependsOn bundle="three"/}
{/scriptjs}

{@renderScript /}

<!-- the unused bundles are not included -->
$script(["one.js"],"one");
$script(["two.js"],"two");
$script.ready(["one","two"], function(){
$script(["three.js"],"three");
})
$script.ready(["two","three"],function(){
});