document-ready-promise

A simple ES2015 Promise-based "document ready" event handler.

Usage no npm install needed!

<script type="module">
  import documentReadyPromise from 'https://cdn.skypack.dev/document-ready-promise';
</script>

README

document-ready-promise

A simple promise-compatible "document ready" event handler with a few extra treats.

Works in any browser that supports Promises or with a good polyfill.

With browserify/webpack:

const ready = require('document-ready-promise')

ready().then(function() {
  // Party time.
})

If in a non-commonjs environment, just include the script. It will attach document.ready for you.

<script src="document-ready-promise.js"></script>
<script>
document.ready().then(function() {
  // voila!
})
</script>

The document.ready promise will preserve any values that you may be passing through the promise chain.

// Using ES2015 and window.fetch
fetch(new Request('kitten.jpg'))
  .then(response => response.blob())
  .then(document.ready)
  .then(blob => document.querySelector('img').src = URL.createObjectURL(blob))