Skip to content

Latest commit

 

History

History
61 lines (51 loc) · 1.51 KB

README.md

File metadata and controls

61 lines (51 loc) · 1.51 KB

Static Loader

Provides dynamic loading of remote JavaScript and CSS resources

  • Loads your files asynchronously, JS and CSS
  • Updating CSS files without page reloading
  • Fires onload callback when all files is loaded

Quickstart

  1. Add a script tag into your page:
<script src="/js/staticloader.js"></script>
  1. Initialize module:
<script>window.staticLoader = new window.staticLoader();</script>
  1. Use it:
window.staticLoader.load([
  'relative/path/to/file.css',
  'http://external/path/to/file.css',
  '/absolute/path/to/file.js'
], function () {
  // onload callback
});

Arguments

Files argument

  • as Array The loads order will be the same order as elements of array

    window.staticLoader.load([
      '/path/to/large/file.js',
      '/path/to/small/file.js',
      {
          url: '/path/to/file.css?v=123'    // ?v=123 - used as a fallback version detection
      },
      '/path/to/another.css'
    ]);
  • as Object

    window.staticLoader.load({
      url: '/path/to/file.css',   // Required.
      id: 'specifiedId',          // Optional. Can be used to update files with different url.
      version: 123                // Required if you want to update CSS file, also can be 
    });                           // included into url with GET parameter "v".
  • as String

      window.staticLoader.load('/path/to/file.css');

Function argument

Some logic that should be executed when CSS and JavaScript files will be loaded.