For a quick intro, check out this presentation.
So where does Deferrify come in?
Unfortunately splitting code for deferred loading currently requires developers to manually split their code into "during page load" and "later" parts. This often requires an intimate understanding of the code in order to determine which functions are really needed during page loading. Deferrify can automatically determine which code is required during load, and split everything else into strings to defer parsing, and optionally into a separate file for deferred loading.
The easiest way to get started with Deferrify is using Node.js. If you already have Node installed, simply execute the deferrify script, found in the root of the source tree.
If you prefer using the SpiderMonkey JS shell, you can run deferrify with
Deferrify can also run in the browser, although setting this up is a bit more complicated. See the sources of this presentation for more details.
For detailed usage instructions, check out:
Compile input.js to output.js, deferring parsing of all functions larger than 100 bytes:
deferrify -Z 100 -o output.js input.js
Now split all deferred strings into a new file, split.js, as well:
deferrify -Z 100 -Zs split.js -o output.js input.js
Instrument with profiling code (no deferring yet):
deferrify -Zi -o output.js input.js
Once the code has been instrumented, load it in the browser. When the page has finished loading, hit the "Show Profile" link, and save the resulting profile (for example, as calls.profile). Deferrify can now read this profile and optimize the deferred code to not defer anything called as part of the page load:
deferrify -Z 100 -Zp calls.profile -o output.js input.js