Oct
26
Conditional Upload of jQuery: Paul Grenier and Christophe Humbert
My two favorite jQuery gurus Paul Grenier and Christophe Humbert had a quick email exchange regarding how to include conditional jQuery uploading in their scripts. I thought it would be enlightening for Power Users who have been following jQuery for Everyone and Path to SharePoint to see the discussion.
Here’s the exchange:
Christophe Humbert:
As workshop users want to include several Web Parts on the same page, I am looking for a way to include conditional jQuery loading. The most common methods are DOM insert and the document.write you are using. However, from what I read, it seems that both methods are asynchronous, which means that there is no guarantee that jQuery is loaded before the custom script starts executing.
How is this working for you? Have you noticed any weird behavior?
Paul Grenier:
That’s not entirely accurate because it depends on the browser. See this article: http://www.stevesouders.com/blog/2009/04/27/loading-scripts-without-blocking/ and look at the section about “preserves execution order”. Since we’re dealing with IE, you want either the defer method or the one I’m using to preserve order.
Christophe Humbert:
Thanks, the article you sent and the articles it points to look very interesting. From what I (quickly) read, it is not clear what the order will be between document.write and an inline script. I’ll need to take a closer look.
I am trying to make my scripts work cross-browser (for internet sites for example), not just IE. I agree about the defer option and I think I’ll try this first. It used to be IE only but it seems to be now accepted by most browsers: http://code.google.com/p/doctype/wiki/ScriptDeferAttribute
How does this true up with Jan Tielen’s Assembly-Free jQuery in SharePoint Sites Using the SmartTools jQueryLoader? Is his method better/worse/too complicated?
M.