November 7th, 2006
I've been reading this new book, AJAX Patterns by Michael Mahemoff. Now I'm a seasoned developer and javascript is like a second language for me, but I haven't been keeping on abreast of all the nifty techniques flinging out of the AJAX world in the past 15 months. Within the first 40 pages of this book I learned a dozen new things, and had quite a few "eureka" moments, so I highly recommend it.
One technique that I'm eager to push into production is the idea of "javascript on demand". I have a personal arsenal of hundreds of really killer custom functions, but who wants to load all of that into each page if they're not going to be used on that page? When I use a server control that requires a javascript ingredient (say, UI elements like a 2-panel selection tool, or a slider bar), wouldn't it be nice if those controls grabbed the javascript they require from a library, and load them as needed, without any fuss? The answer: javascript on demand.
Imagine function A which requires function B and C to execute. And I have a server widget X which requires A to be available. Using JOD, I can force control X to load up JS function A. Then the scripts within function A can load B and C as dependents.
The core method of JOD is simple DHTML:
   var head = document.getElementsByTagName("head")[0];
   script = document.createElement('script');
   script.id = 'extraScript';
   script.type = 'text/javascript';
   script.src="/jslibrary/zipvalidator.js"Â
   head.appendChild(script)
in that example, I've just loaded a new validator function on demand by putting a new <script> element into the <head>. I might do this if I chose "USA" as my country, then I'd make the ZIPÂ validator available. But if I chose "Canada", I would load up the Postal Code validator function instead.
The possibilities for richly enhanced UI widgets is interesting; I think first I'll look for ways it can simplify client-side reporting challenges like "clickmap" tracking, cookie detection, and multivariate A/B testing.
Â
Filed under Uncategorized
October 1st, 2007 at 10:08 am
[...] I could have built JOD from scratch, but since there is already an “Assets” class in Mootools, I’m using it (I’ll expand on my opinion of Mootools in another post). The strategy leans significantly on Mootools, and its Assets object http://docs.mootools.net/Remote/Assets.js That Mootools has an Asset class is proof enough that this strategy is not a fanciful hack; it’s a well-established pattern. see: http://ajaxpatterns.org/On-Demand_Javascript see: http://www.ianring.com/blog/2006/11/javascript-on-demand/ This technique is also known as “Lazy Loading†. It has the following benefits: [...]
September 12th, 2008 at 8:29 am
[...] I could have built JOD from scratch, but since there is already an “Assets” class in Mootools, I’m using it (I’ll expand on my opinion of Mootools in another post). The strategy leans significantly on Mootools, and its Assets object http://docs.mootools.net/Remote/Assets.js That Mootools has an Asset class is proof enough that this strategy is not a fanciful hack; it’s a well-established pattern. see: http://ajaxpatterns.org/On-Demand_Javascript see: http://www.ianring.com/blog/2006/11/javascript-on-demand-140/ [...]