I have used
My clean aproach...
if (document.readyState !== 'loading') init() else document.addEventListener('DOMContentLoaded', init); function init() { console.log("Do it !"); ... }