23:37
:31
2016
Easy dynamic loading of CSS/JS
- Resume:
Small script to easily load multiple CSS and JS with a callback when all is done.
- Version:
1.1.2
- Size:
1kb
- License:
MIT License
- Copyrights:
Renan Lavarec
I needed to load easily js and css and get a callback in the end, I just create my own small lib :)

Easy dynamic loading of CSS/JS

Small script to easily load multiple CSS and JS with a callback when all is done.

A percentage is returned base on the number of files already loaded.

Dependencies

  • No dependency

Demos

There is 2 demos inside demos directory

  • demo-basic.html:

    • It show how to use it with a very basic sample.

  • demo-percentage.html:

    • It show how to use it and get percentage informations.

How to use it

  • Html:

You just need to include the file.
    <script language="JavaScript" src="tr.easydynamic_load_css_js.min.js"></script>
  • Javascript:

    • The library contain 3 functions

      • LoadJSAndCSS: to load several css and/or js dynamically

    // TR.LoadJSAndCSS
    var tListJStoLoad  = [ 'script1.js', 'script2.js', 'script3.js' ];
    var tListCSStoLoad = [ 'link1.css', 'link2.css' ];
    
    function CallBackWhenDone()
    {}
    
    function CallBackPercentage( _percentage )
    {}
    
    // tListJStoLoad or tListCSStoLoad can be undefined
    TR.LoadJSAndCSS(tListJStoLoad, tListCSStoLoad, CallBackWhenDone, CallBackPercentage);
  • LoadJS: to load a single js dynamically

    function CallBackWhenDoneJS()
    {}
    TR.LoadJS('script1.js', CallBackWhenDoneJS);
  • LoadCSS: to load a single css dynamically

    function CallBackWhenDoneCSS()
    {}
    TR.LoadCSS('link1.css', CallBackWhenDoneCSS);

Reason

I needed to load easily js and css and get a callback in the end, I just create my own small lib :)

Changelog

  • Version 1.1.1

    • Remove default variables.

  • Version 1.1.0

    • Added percentage information.

  • Version 1.0.0

    • Release