function ready(callback) {
  var state = document.readyState;

  if (state === 'complete' || state === 'interactive') {
    return setTimeout(callback, 0)
  }

  document.addEventListener('DOMContentLoaded', callback);
}
Fork https://github.com/bendrucker/document-ready/blob/master/index.js