I'm working on a javascript widget (with jQuery) that others can embed on their webpage doing something like this:
<html>
<head><script type='text/javascript' src="http://example.com/widget.js"></script></head>
<body>
<script type='text/javascript' id="widgetAnchor">
showWidget(1,2);
</script>
</body>
</html>
My widget needs to load several items:
- jQuery
- jQueryUI
- widget.css
- data from my server (using jQuery.getJSON)
- an image from my server (when the img tag is added to the document)
I'm currently loading 2, 3, and 4 using a chaining technique, which is slow. Since the three are independent, I would like to load these simultaneously. Could I do this by not using a callback function, and instead using jQuery.load() to signal that all of these are present and I can proceed with rendering the widget?
Also, is there way to load the image in parallel with 2, 3, and 4? Would it make sense to immediately add the img tag to the widget and then later moving it to the right place when I am rendering the widget?