All Projects → pyrsmk → Toast

pyrsmk / Toast

Licence: mit
A modern JS/CSS asset loader, written in TypeScript.

Programming Languages

javascript
184084 projects - #8 most used programming language
js
455 projects

Projects that are alternatives of or similar to Toast

assetter
Assets manager for PHP. Allow manage CSS and JS files in website and its dependencies. Also allows refresh cache in browsers by adding revisions of loaded files. Builtin plugins to compile SASS and/or LESS styles to CSS just-in-time.
Stars: ✭ 14 (-88.14%)
Mutual labels:  loader, assets-management
Eclipseloading
🌞 日食加载动画
Stars: ✭ 114 (-3.39%)
Mutual labels:  loader
Typeorm Loader
A database-aware data-loader for use with GraphQL and TypeORM.
Stars: ✭ 86 (-27.12%)
Mutual labels:  loader
Nvactivityindicatorview
A collection of awesome loading animations
Stars: ✭ 10,031 (+8400.85%)
Mutual labels:  loader
React Native Skeleton Content Nonexpo
A customizable skeleton-like loading placeholder for react native projects not using expo.
Stars: ✭ 92 (-22.03%)
Mutual labels:  loader
Vkbind
Single file Vulkan API loader.
Stars: ✭ 110 (-6.78%)
Mutual labels:  loader
Hr Payroll
HRM is a Modern and responsive Human Resource Management System. It is developed by PHP and Codeigniter framework. It is designed and developed for office management and company employee management.
Stars: ✭ 86 (-27.12%)
Mutual labels:  assets-management
Ghidra Gamecube Loader
A Nintendo GameCube binary loader for Ghidra
Stars: ✭ 117 (-0.85%)
Mutual labels:  loader
Vue Content Placeholders
Composable components for rendering fake (progressive) content like facebook in vue
Stars: ✭ 1,547 (+1211.02%)
Mutual labels:  loader
Vue Svg Inline Loader
Webpack loader used for inline replacement of SVG images with actual content of SVG files in Vue projects.
Stars: ✭ 105 (-11.02%)
Mutual labels:  loader
Csv2db
The CSV to database command line loader
Stars: ✭ 102 (-13.56%)
Mutual labels:  loader
Graphql Mongoose Loader
GraphQL Mongoose Loader helpers
Stars: ✭ 98 (-16.95%)
Mutual labels:  loader
Node Hot Loader
Hot module replacement (hot reload) for Node.js applications. Develop without server restarting.
Stars: ✭ 111 (-5.93%)
Mutual labels:  loader
Grow Loader
A webpack loader to split class methods by decorators
Stars: ✭ 89 (-24.58%)
Mutual labels:  loader
Vue Api Request
Control your API calls by using an amazing component which supports axios and vue-resource
Stars: ✭ 116 (-1.69%)
Mutual labels:  loader
Stryker
Multi-purpose proof-of-concept tool based on CPU-Z CVE-2017-15303
Stars: ✭ 86 (-27.12%)
Mutual labels:  loader
Mkloader
Beautiful and smooth custom loading views
Stars: ✭ 1,377 (+1066.95%)
Mutual labels:  loader
Materialactivityindicator
Material Activity Indicator
Stars: ✭ 109 (-7.63%)
Mutual labels:  loader
Style Loader
Style Loader
Stars: ✭ 1,572 (+1232.2%)
Mutual labels:  loader
Swiftloader
A simple and beautiful activity indicator written in Swift
Stars: ✭ 116 (-1.69%)
Mutual labels:  loader

Toast v3

Toast is a promise-based JS/CSS loader for the browser. It aims to optimize web site performance by loading your assets asynchronoulsy.

Quick note on IE9/10 support

Support has been dropped for these browsers since Mocha/Sinon (which is used to run our tests) does not support them anymore. Since it would take some time to migrate the tests, that IE9/10 is not supported anymore by Microsoft, and that its market share have dropped under 1%, we took the decision to stop our support too.

For the time being, Toast 3.0.2 will work with IE9/10. Since the code shouldn't evolve too much, you should be safe in the far future until Toast reaches a breaking change.

Compatibility list

Toast is tested against:

  • Chrome 83 (older version should be good too)
  • Firefox 76 (older version should be good too)
  • Edge 83 (older version should be good too)
  • Safari 11-13
  • IE11
  • Android 4.4-10
  • iOS 10-13

Set up

The preferred way to load toast in your application is to install it via NPM (or Yarn), and import it directly in your codebase (it has a very small footprint, and the sooner it's loaded the better).

npm install toast-loader

You have several options to load it in your code depending on your application environment:

  • by inlining it in a <script> tag
  • with const { toast } = require('toast-loader')
  • with import { toast } from 'toast-loader'

You can also load it from the usual <script> tag in your <head>, but I advise you to use a CDN instead of loading it from your own server:

<head>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
</head>

Be sure to use the latest version of Toast and keep a fixed version in production environment (to avoid breaking changes).

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')
}
const handleErrors = error => {
    console.log(error)
}

toast.js('http://some.cdn.com/jquery.js')
    .then(() => {
        toast.js('http://some.cdn.com/jquery-myplugin.js')
            .then(() => $('.someClass').myPlugin())
            .catch(handleErrors)
        })
    })
    .catch(handleErrors)
await toast.all([
    'assets/css/styles1.css',
    'assets/js/script1.js',
    'assets/js/script2.js',
    'assets/css/styles2.css',
    'assets/js/script3.js',
])
console.log('Everything has been loaded, yay!')

toast.all relies on automatic extension detection. If your URL does not contain a file extension you'll need to use Promise.all instead and do some extra work:

await Promise.all([
    toast.css('assets/css/styles1'),
    toast.js('assets/js/script1'),
    toast.js('assets/js/script2'),
    toast.css('assets/css/styles2'),
    toast.js('assets/js/script3'),
])
console.log('Everything has been loaded, yay!')

Browser compatibility

  • IE10 support (and prior) has been removed since it's not supported by Microsoft anymore and their market share have dropped under 1%
  • Toast is using built-in promises, so if you need to support I11, you must add the promise-polyfill library before loading toast: here's the compatibility table for the Promise feature
  • for your information, IE11 and Edge never trigger error event on CSS loading if something goes wrong; keep this in mind when you're using catch promise block
  • if you want to learn more about SCRIPT/LINK node feature support details, you can take a look at this compatibility table

Development

Install the dependencies with:

npm install

And build the lib with:

npm run build

Look at the scripts in package.json file for more details.

Testing

Tests are written with Mocha and Sinon, and can be run with:

npm run test

It should open your default browser (under a Gnome desktop). If not, just drag and drop the tests/index.html in your preferred browser.


These tests are just for local debugging when in development phase but they need to pass the Karma tests. Karma is a tool to execute unit tests on remote browsers with Selenium/Appium. To be able to run them, you'll need an account on BrowserStack. It's the only service that have a free plan for open-source projects.

When your account is ready, you must prepare your environment by setting global variables in a file that is loaded when your console initializes, like .bashrc, .zshrc or .profile:

  • go to the Automate page
  • display your ACCESS KEY (it's accessible on the right of the search bar)
  • set your env variables like so:
    export BROWSERSTACK_USERNAME="<your_username>"
    export BROWSERSTACK_ACCESS_KEY="<your_access_key>"
    

Then, run the karma tests with:

npm run karma:all

The results will be displayed in the console and on the Automate page of your account.

If you want to only run tests on a specific browser you can use one of the following commands:

npm run karma:chrome
npm run karma:firefox
npm run karma:safari13
npm run karma:safari12
npm run karma:safari11
npm run karma:edge
npm run karma:ie11
npm run karma:android10
npm run karma:android9
npm run karma:android8
npm run karma:android7
npm run karma:android6
npm run karma:android5
npm run karma:android44
npm run karma:ios13
npm run karma:ios12
npm run karma:ios11
npm run karma:ios10

Note: I don't know why but the tests can be unstable in some VMs when running all Karma tests in parallel; don't hesitate to re-run tests on a specific VM to verify.

License

MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].