I have a small javascript resource that can be preloaded, lazy loaded or loaded on demand. When it is initiated, it adds some things to the DOM. It has a low priority, and if it is preloaded, it can wait for the onload event to fire before it starts, but if it is lazy, it can work and fire immediately.
He is currently checking to see if the footer element identifier exists to determine if he should add an event listener to the window's onload event or just fire it. eg
if ( document.getElementById("footer") ){ Init() } else { if (window.addEventListener){...} else if (window.attachEvent){...} }
Although this currently works, it is certainly a pretty bad solution. Any suggestions not related to jQuery to improve this are greatly appreciated!
source share