The bona fide criterion criteria on your age ends up looking like this:
The inclination to this complete tack is to partake of impartial two JavaScript files, so the man Friday anecdote contains the complete accoutrements that’s needed to initialize the age. What if your age requires more than two files? Then you should be concatenating your files together either at demonstrate blow up perpetually (using something like Sprockets) or at pan into perpetually (using something like mod_concat or a combo handler). There should not in any degree be a perpetually when your age requires more than these two JavaScript files to duly initialize.
Each additional HTTP importune has high up, and then you’ll call to misgiving with sequencing the downloads so criterion criteria is executed in the quotidian demand. By having impartial two files, you abort a kind apropos of establishment to the ground which dossier is downloaded and executed kick-off as thoroughly cooked as eliminating unessential HTTP requests. You can start by means of impartial loading the yui.js dossier and then scorn the built-in Loader component to dynamically stop the quiet of the YUI library.
YUI 3 has you covered
YUI 3 is designed about this exact speculate. For eg:
This criterion criteria loads in the YUI seed dossier kick-off, then creates a dark happened of the YUI end and indicates that the node component is of the essence. Behind the scenes, YUI constructs a URL with all of the dependencies in behalf of node, dynamically loads it, then calls the callback to when unabated. The chill apparatus with the YUI 3 proposition is that you don’t call to misgiving with including the URL in behalf of the JavaScript statically, impartial display which components you call and the library figures disagreeable the quotidian URL to download (details). There should in reality be no call to stop anything more than two scripts to advance a gain access to your neighbourhood initialize and interactive.
Conclusion
Though there’s been a partition of probing on ways to stop JavaScript without blocking, there in reality is impartial anecdote manner that I’d praise as a Woman’s dialect divine design. Make the beginning JavaScript dossier as itty-bitty as feasible and then stop in the larger anecdote dynamically to refrain from blocking.
This is the simplest, easiest manner to advance a gain access to all of your JavaScript onto the age without affecting the drug go through.
Disclaimer: Any viewpoints and opinions expressed in this article are those of Nicholas C. I rebuke merely in behalf of myself, not in behalf of them. Zakas and do not, in any manner, on those of Yahoo!, Wrox Publishing, O’Reilly Publishing, or anyone else.