Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

toast-loader

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

toast-loader

A modern JS/CSS asset loader

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
549
increased by0.37%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 23 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc