Download the PHP package nswdpc/silverstripe-async-loader without Composer
On this page you can find all versions of the php package nswdpc/silverstripe-async-loader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nswdpc/silverstripe-async-loader
More information about nswdpc/silverstripe-async-loader
Files in nswdpc/silverstripe-async-loader
Package silverstripe-async-loader
Short Description An asynchronous assets loader for Silverstripe 4 using loadjs
License BSD-3-Clause
Informations about the package silverstripe-async-loader
Async Requirements Loader
This module provides a backend to load requirements asynchronously using loadjs
The goal is to make requirements loading light without blocking page load and to support the separation of critical and non-critical requirements.
loadjs itself is loaded as an inline script within the page
Supports Silverstripe 4.0+
Usage example
Bundles
loadjs uses dependency 'bundles' to manage loading of scripts.
Default requirements bundle
For backwards compatibility scripts loaded via are loaded by loadjs in series and assigned to the bundle 'requirements_bundle'
See Section 3 of the loadjs documentation
Once all scripts are loaded, a callback is fired and dispatches a DOM event
Custom scripts that require a script to be loaded prior to firing can listen for this DOM event:
Specific bundles
Scripts that do not depend on anything loaded in a default bundle can be loaded in a non blocking way in their own bundle:
Optionally with a callback... if you need to do something after a bundle loads
See Section 1 of the loadjs documentation
You can include multiple scripts in the bundle
See Section 2 of the loadjs documentation
CSS
CSS requirements are loaded in blocking mode by default within the tag.
You can alternatively load CSS in non-blocking mode via a backend bundle:
Be aware that unless you load in styles that set up a basic/acceptable above-the-fold layout, you will most likely get a FOUC until stylesheets loaded this way are applied. It's fast, but ugly.
Refer to Section 5 of the loadjs documentation on CSS loading notes.
Page placement
If you wish, place the HTML comment in your page template where you would like JS requirements to be placed. The backend will replace this comment with the JS requirements found. If you do not do this, the JS requirements will be loaded before the closing body tag.
Custom scripts
If you have custom scripts that assume a library is loaded, these will most likely fail unless they are run after their dependency loads. To ensure that they run correctly, apply them in the relevant bundle callback or in an event listener for
Custom head tags
These are loaded prior to the closing head tag.
TODO
- For non-critical CSS, support for 'lazy' loading of Requirements::css() placing a stylesheet tag prior to the closing body tag.
Licences
BSD 3-Clause
- loadjs is licensed under the MIT license: https://github.com/muicss/loadjs/blob/master/LICENSE.txt