A flexible JS and CSS static resource file loader for Salesforce Aura
Switch branches/tags
Nothing to show
Clone or download
Latest commit d2f5c67 Mar 3, 2015
Failed to load latest commit information.
example update example Sep 1, 2014
README.md add package Mar 3, 2015
load.cmp first commit Aug 29, 2014
loadController.js first commit Aug 29, 2014
staticResourcesLoaded.evt first commit Aug 29, 2014



A simple and fast Salesforce Aura component that can be used to load JS and CSS static resources in series, parallel, or in any other fashion.

Unmanaged Package:


##Getting started 0. Simply install unmanaged package from here: https://login.salesforce.com/packaging/installPackage.apexp?p0=04tB000000017Gl


  1. Create load.cmp, loadController.js and staticResourcesLoaded.evt files in your org and copy contents from this here.

  2. Change namespace from jam to your org's namespace in all those files.

  3. Load the load component into your application's .app file (say myAuraApp.app) like below.

    // Loads css1.css, fileParallel1.js and fileParallel2.js in parallel. 
    // After all 3 are loaded it async loads fileSeries1.js and finally async loads DEPENDENT_on_fileSeries1.js.
    //If the Static resources are NOT inside a zip file, use "sfjs" and "sfcss" 
    as extensions(see down below for more details). 
  4. Listen to staticResourcesLoaded in your component and do something.

    <!-- listen to staticResourcesLoaded and call initScripts function inside controller -->
    <aura:handler event="jam:staticResourcesLoaded" action="{!c.initScripts}"/>

##Various Ways Of Using load.cmp:

  1. Load CSS /JS files asynchronously but one-by-one from left to right(Great for dependency but not speed).

  2. Load files asynchronously and in parallel (Great for speed but not for dependency management).

  3. Load some in series and some in parallel (Common usecase)

    Tip: Put your CSS files, non-dependent files in filesInParallel and only dependent files in filesInSeries


Note: The library prioritizes and loads all files in filesInParallel before loading files in filesInSeries.

##Handler: Once all the files are loaded (irrespective of pattern), the library fires 'APPLICATION' level event: staticResourcesLoaded.

<aura:handler event="jam:staticResourcesLoaded" action="{!c.initScripts}"/>

##Static Resource File Paths:

  1. Static Resources that are not in Zip file (.sfjs and ".sfcss)

    Salesforce doesn't allow files to have .js or .css extensions if they are not within a Zip file. To load such direct or raw file resource, use /resource/<filename>.sf<filetype> filepath.

    // JavaScript file: /resource/myJsFile.sfjs
    // CSS file: /resource/myCssfile.sfcss

    Note: This tells the library what kind of file it is AND that it doesn't have a file extension unlike files inside a zip file.

  2. Static Resources that are in Zip files.

    To load a CSS or JS file in static resource inside a Zip file use: /resource/zipfileResourceName/path/to/file.cssOrJs



  1. This fires event at "APPLICATION" level "namespace:staticResourcesLoaded" event. So you should use it at Application-component level.

  2. You can also use it inside a "component" but you have make sure to ignore events after getting the first one.

    //In Handler component's controller, add some code like this.
    if(!component.alreadyreceivedEvent) {
    	component.alreadyreceivedEvent = true;
    	// do something w/ the event..
    } else {
    	return; //ignore further events	
  3. Internally uses MODIFIED version of l.js (https://github.com/malko/l.js)

##Example App You can test it by loading the example BootstrapApp.app inside example directory.

  1. Create an Aura app with the with filenames BootstrapApp.app, BootstrapApp.cmp, BootstrapAppController.js from developer console.
  2. Change namespace from jam to YOUR_NAMESPACE.
  3. Upload aotp_bootstrap.zip and jquery.js to static resources with the same name ("aotp_bootstrap" and "jquery").
  4. Open BootstrapApp.app. Click on preview.
  5. 'click on the Launch Modal - JavaScript to see if the JavaScript dialog shows up.