Skip to content

Instantly share code, notes, and snippets.

@ivoputzer
Created November 3, 2017 11:09
Show Gist options
  • Save ivoputzer/ee704793f78f3e2a961ab8d046464ad2 to your computer and use it in GitHub Desktop.
Save ivoputzer/ee704793f78f3e2a961ab8d046464ad2 to your computer and use it in GitHub Desktop.
different dom ready implementations in vanilla javascript
function ready (fn) {
if (typeof fn !== 'function') return
if (document.readyState === 'complete') return fn()
document.addEventListener('DOMContentLoaded', fn, false)
}
ready(function domIsReady() {
console.info('dom is ready now')
})
function ready (fn, {requestAnimationFrame} = window) {
if (document.body) return fn()
requestAnimationFrame(ready.bind(null, fn, {requestAnimationFrame}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment