Toast v3
Toast is a promise-based asset loader for JS and CSS files. It aims to optimize web site performance by loading and deferring the needed assets only.
Since it have a small footprint Toast can be loaded as soon as possible on the HEAD
tag.
As a side note: Toast is packaged as an UMD module.
Install
yarn add toast-loader
The API
toast.css(url: string): Promise
toast.js(url: string): Promise
toast.all(urls: string[]): Promise
Examples
if (dark_mode === true) {
toast.css('styles/dark.css')
} else {
toast.css('styles/light.css')
}
toast.js('http://some.cdn.com/jquery.js').then(() => {
toast.js('http://some.cdn.com/jquery-myplugin.js').then(() => {
$('.someClass').myPlugin()
})
})
toast.all([
'assets/css/styles1.css',
'assets/css/styles2.css',
'assets/js/script1.js',
'assets/js/script2.js',
'assets/js/script3.js',
]).then(() => {
console.log('Everything has been loaded, yay!')
})
Browser compatibility
IE9-IE11 and Edge never trigger error
event on CSS loading if something went wrong. Keep this in mind when you're using catch
promise block with Toast.
If you want to look at some feature supporting details, you can take a look at this compatibility table.
It worth noting that Toast has been designed to be compatible with modern browsers and IE9+. Supporting other older browsers would have a negative impact on the library size.
Development
Install the dependencies with:
yarn install
Build the lib with:
yarn build
Testing
Tests are written with Mocha and Chai and run with Karma on LambdaTest.
First, you will need to set up you're own environment:
- create your account on LambdaTest
- download the tunnel software, it will act as a gateway between Karma and LambdaTest
- verify that the
LT
command is accessible (e.g. in the PATH
) - get your credentials from the Automation page, they are located under the key icon
- set them in your environment, per example in your
.bashrc
:
export LT_USERNAME="<your_username>"
export LT_ACCESS_KEY="<your_access_key>"
Finally, you can run the tests with:
yarn test
They will be run under the following browsers:
- Chrome 73
- Firefox 66
- Edge 18
- IE 9-11
- Safari 12
If needed, you can run the tests under only one browser with:
yarn chrome
yarn firefox
yarn edge
yarn ie11
yarn ie10
yarn ie9
yarn safari
License
Licensed under the MIT license.