// Check if DOM has already loaded as we're loading async
if(['interactive', 'complete'].indexOf(document.readyState) >= 0) {
  init();
} else {
  document.addEventListener('DOMContentLoaded', init);
}

// When DOM is ready
function init() {
}

// Check if DOM has already loaded as we're loading async
['interactive', 'complete'].indexOf(document.readyState) >= 0
  ? init()
  : document.addEventListener('DOMContentLoaded', init);

// When DOM is ready
function init() {
}

Write DOM load check more efficiently
Write DOM load check more efficiently
