load-promises
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

loadPromises

Expose the page load events as promises. Works in any browser that supports promises, or that has a compatible polyfill.

Install

With NPM

$ npm install load-promises

With Yarn

$ yarn add load-promises

Usage

With webpack. The package has a module field. Tree shaking is possible if you only use one of the events.

import { DOMContentLoaded, windowLoad } from 'load-promises';
 
// Equivalent of $(document).ready();
DOMContentLoaded().then(() => {
  // ...
});
 
// Equivalent of $(window).load();
windowLoad().then(() => {
  // ...
});

In a browser. Both promises are namespaced in loadPromises

<html>
  <head>
    <script src="loadPromises.umd.js"></script> 
    <script>
      // Equivalent of $(document).ready();
      loadPromises.DOMContentLoaded().then(function() {
        // ...
      });
 
      // Equivalent of $(window).load();
      loadPromises.windowLoad().then(function() {
        // ...
      });
    </script> 
  </head>
  <body></body>
</html>

Readme

Keywords

Package Sidebar

Install

npm i load-promises

Weekly Downloads

6

Version

2.0.2

License

MIT

Unpacked Size

5.79 kB

Total Files

7

Last publish

Collaborators

  • afgomez