12:22
:56
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.1
- 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 :)
- Dependencies:
No dependency
- How to use it:
- html:

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

- Javascript:

The library contain 3 functions
  • LoadJSAndCSS: to load several css and/or js dynamically

  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    // TR.LoadJSAndCSS
    var tListJStoLoad = [ 'script1.js', 'script2.js', 'script3.js' ];
    var tListCSStoLoad = [ 'link1.css', 'link2.css' ];
    // Callback when all done
    function CBWhenDone()
    {}
    // Callback percentage
    function CBPercentage( _percentage )
    {}
    // tListJStoLoad or tListCSStoLoad can be undefined
    TR.LoadJSAndCSS(tListJStoLoad, tListCSStoLoad, CBWhenDone, CBPercentage);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


  • LoadJS: to load a single js dynamically

  • 1
    2
    3
    function CallBackWhenDone()
    {}
    TR.LoadJS('script1.js', CallBackWhenDone);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


  • LoadCSS: to load a single css dynamically

  • 1
    2
    3
    function CallBackWhenDone()
    {}
    TR.LoadCSS('link1.css', CallBackWhenDone);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    - Change log:
    - Version 1.1.1
    * Remove default variables.

    - Version 1.1.0
    * Added percentage information.

    - Version 1.0.0
    * Release the lib.