Hold off that javascript code until Document Object Model (DOM) is safe to manipulate.
Table of Content
Library
youreadydom
is a tiny, fully tested javascript library, written in ES6. It provides the same functionality as jQuery .ready()
method without jQuery's overhead. Unlike jQuery, youreadydom
is promise based—it's modern 😎. Check out the examples below.
You can add this to your list of reasons for why you might not need jquery anymore.
For those unfamiliar with jQuery .ready()
method, it provides a way to run javascript code as soon as the Document Object Model (DOM) has finished loading.
'DOMContentLoaded'
Most browsers provide the 'DOMContentLoaded' event which provides similar functionality but differs in that it does not execute any listener which is added after the event is fired. Internally this library adds a single 'DOMContentLoaded' event listener only if DOM content has not already loaded. The listener is removed once the event is fired and all handlers are executed in the order they are added.
/** Comparison */
window.onload
The 'load' event on window
is fired when all resources on the page have finished loading. This includes images.
Browser Support
Chrome | Safari | IE* / Edge | Firefox | Opera |
---|---|---|---|---|
Yes | Yes | 9+ | Yes | Yes |
Note: Internet Explorer is supported as long as Promise is polyfilled. Check out polyfill.io for automatic browser polyfills!
Installation
This module is distributed via npm which is bundled
with node and should be installed as one of your
project's dependencies
Using npm
> npm install --save youreadydom
Using yarn
> yarn add youreadydom
Using CDN (Not recommended)
<!-- Exposes `domReady` global function -->
Examples
Callback
Lib example using Javascript callbacks
'use strict' var domReady = var $ = documentquerySelector /** Oldschool 👍 */
Promise
Lib example using Javascript Promises
const renderApp = ReactDOM /** Enjoy a promise 😃 */
Async Function
Lib example using Javascript async functions
/** Just `await` it 😍 */; { const data = await await const foo = footextContent = data}
Contributors
License
MIT