l.js

l.js is another simple/tiny javascript/css loader

Този скрипт не може да бъде инсталиран директно. Това е библиотека за други скриптове и може да бъде използвана с мета-директива // @require https://update.greatest.deepsurf.us/scripts/23419/634829/ljs.js

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey .

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

Автор
jaeger
Версия
0.0.1.20181007120505
Създаден
22.09.2016
Обновен
07.10.2018
Размер
8 КБ
Лиценз
Няма

Github:https://github.com/jae-jae/l.js

l.js is another simple/tiny javascript/css loader

Modify by Jaeger [email protected]

Modify log

  • 2016-09-19:Add exec and execJs function; In order to load the js file and execute js script, but don't insert the js file link into the document header.

features

  • parallel script / css loading
  • callback after script loading (css support callback too but are executed imediately)
  • tiny only 2.1ko uglifyed, less than 1ko gziped (at least for latest revision)
  • may load in order to preserve dependencies
  • support aliases for simpler calling
  • on demand loading
  • only one script tag required
  • clear syntax
  • successive load of same file will load it once but execute all callbacks associated
  • can dumbly check already inserted tags at load time
  • may use a fallback url on error (only for js files and with error events compatible browsers)

examples

loading ljs and another libs with one single tag

<script src="l.js">
    ljs.load('myLib.js',function(){ /* your callback here */});
    ljs.exec('myLib.js',function(){ /* your callback here */});
</script>

loading some scripts in parallel others in order

<script src="l.js">
    ljs
        .load('myLib.js')
        .load('myRequiredLib.js','myDependentLib.js',function(){ /* your callback here */})
    ;

    ljs
            .load('myLib.js')
            .exec('myRequiredLib.js','myDependentLib.js',function(){ /* your callback here */})
        ;
</script>

second load will be executed in parallel of first load but myDependentLib.js won't load before myRequireLib.js is loaded

<script src="l.js">
    ljs.load(['myLib.js','myRequiredLib.js'],'myDependentLib.js',function(){ /* your callback here */});
</script>

this will load myLib.js and myRequiredLib.js in parrallel and wait for them before loading myDependentLib.js

using some aliases for simpler loading

<script src="l.js?checkLoaded"> // <- adding checkLoaded to the url will dumbly check already inserted script/link tags
    ljs
        .addAliases({
            jQuery:'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js#jqueryId' // <- script tag will have attribute id=jqueryId
            ui:[
                'jQuery'
                ,'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js'
                ,'myUITheme.css'
            ]
        })
        .load('ui',function(){
            /* work with both jquery and jquery-ui here */
        })
    ;
</script>

define a fallback url

l.js also support a fallback url for javascript files in case you want to try to get the resource from another location on loading failure You can define this fallback url parameter like you define ids. The difference is you will prefix with #= instead of # alone

<script src="l.js">
    ljs.load('http://domain.com/myLib.js#=/myfallback.js#myid',function(){
        /*
            generated script tag will have myid as id and will try to load /myfallback.js if it fail to load http://domain.com/myLib.js
        */
    });
</script>

this piece of code is dual licensed under MIT / GPL Hope this help, code review, suggestions, bug reports are welcome and appreciated.