In.js Docs

current version: 0.1.9-stable

In.js is a light framework that can manage dependency of the modules, most important,you can load them on-demand,asynchronous and multi-threaded.

philosophy of in.js

just in time.

import in.js to your webpage

<script type="text/javascript" src="in.js" autoload="true" core="jquery 1.5.2-min.js"></script>

* License

juicer is published under the apache license and hosted on github. if you find errors or typos please file an issue or a pull request on the repository.

* API

> In.add()

加载三个待执行的javascript模块,分别为mod1、mod2、mod3,其中mod2依赖于mod3.

<script type="text/javascript">
    In.add('mod1',{path:'mod1.js',type:'js',charset:'utf-8'});
    In.add('mod2',{path:'mod2.js',type:'js',charset:'utf-8',rely:['mod3']});
    In.add('mod3',{path:'mod3.js',type:'js',charset:'utf-8'});
</script>

> In() or In.use()

旧版本队列内为顺序加载,如需向后兼容,请事先配置In.config('serial',true)更换为默认串行加载,新版本的队列默认为并行执行, 队列中最后一个函数被视为回调函数,下面的代码会并行加载mod1,mod2,function,并立即执行,三者均加载完毕后执行回调函数。

<script type="text/javascript">
    //真正的加载顺序为 mod1 || mod2 || function -> function[callback]
    var demo=In('mod1','mod2',function() {
        console.log('我跟mod1和mod2是并行的关系');
    },function() {
        console.log('我是回调函数,他们都加载完毕才会触发我');
    });
</script>

> In.ready()

domReady之后加载队列

<script type="text/javascript">
    In.ready('mod1','mod2',function() {
        console.log($);
    });
</script>

> In.later()

延迟加载队列

<script type="text/javascript">
    //延迟3秒加载队列
    In.later(3000,'mod1','mod2',function() {
        console.log($);
    });
</script>

> In.css()

动态注入CSS

<script type="text/javascript">
    In.css('body {background:yellow}');
</script>

Options

{
	serial:false/true,
	core:''
}

if you wanna change the default options, you can use `In.config()`, do like this:

<script type="text/javascript">
    //设置为串行加载模式,兼容旧的写法
    In.config('serial',true);
    //设置核心库,核心库会被所有模块依赖
    In.config('core','jquery 1.5.2-min.js');
</script>