Wednesday, July 30th, 2008
onJSReady Prototype Plug-in
<>p>In a follow-up to our post a few days ago on parallelizing JavaScript loading and firing an event when loading is done, Stefan Hayden wrote a Prototype extension (based on onDOMReady) that makes it easy for you to execute your code when all JavaScript is loaded:- Event.onJSReady(function () { dependent_on_external_js(); });
Related Content:











I dig Stefan’s script, but it pollutes the global namespace/Event object a bit. An alternative would be: http://pastie.org/244187
usage:
Prototype.include(‘test1.js’,'test2.js’,'test3.js’);
document.observe(‘scripts:loaded’, function() {…});
- JDD
Another benefit of jdalton’s version is that it fires custom events the Prototype Way™, rather than relying on an obscure method on Event.
I’m loving jdalton’s update. I’m definitely going to try that out. Cheers!