UNPKG

choo-shortcache

Version:

choo nanocomponent cache shortcut

18 lines (13 loc) 411 B
'use strict' var assert = require('assert') module.exports = ready function ready (callback) { assert.notEqual(typeof document, 'undefined', 'document-ready only runs in the browser') var state = document.readyState if (state === 'complete' || state === 'interactive') { return setTimeout(callback, 0) } document.addEventListener('DOMContentLoaded', function onLoad () { callback() }) }