Thread:Talk:ResourceLoader/Version 2 Design Specification/Top-loaded site scripts/reply

I don't intend to be a nag here, but the title for this thread and the contents of your message are somewhat addressing different, albeit overlapping, issues.

I'll answer them seperately.

Loading scripts from the top of the document

As of ResourceLoader 2 a module can be registered with one of various queue names. The default is 'bottom', which means the all-in-one load request will be initiated from the bottom of the page (after the output of the article, but stilll a fair distance away before the document-ready event).

This queue should be used to load scripts that affect the page independant from on-or-after-load scripts. A good example is the stylesheet that applies to HTML generated by PHP. For example Extension:CodeReview and Extension:LiquidThreads output HTML via PHP through Special pages and other means. The styling for this HTML should be loaded before the rest of the page is loaded (otherwise there'd be a moment of unstyled content, which is bad).

For these scenario's the "position" property of the module registry should be set to "top". Which means the module will be loaded from the top of the page and will, just like any tag does in the, block page execution untill it's parsed and executed.

Load delay

There were some issues in RL1 (most are fixed, some are pending) with the order and speed of the modules loaded. These should not be resolved by injecting the modules earlier (ie. "position" => "top") as this will either fail or have an effect that doesn't do what one might think (either way, it's evading the issue at hand).

Scripts that only affect a later state of the page or bind event handlers should not be loaded from the "top" (because these elements do not exist yet at that time, "top" basically means before exists).

The reason that doing so might have side effects is due to dependancies. If a script wrongly puts itself in the "top" position and depends on another module (ie. jquery.ui.dialogs), that means that all of jquery.ui.dialogs ( and it's dependancies: jquery.ui.core, jquery.ui.widget, jquery.ui.button etc. which also have dependancies that load ) are now all loaded in the top of the page, because that one module needs it. That would slow down the page noticably.

If scripts execute with a delay, please report it as soon as possible. If you can, check out a copy of the current development trunk via Subversion so that you can see if the current solution and improvements work for you and solve the issues you had. (By doing that we can catch and resolve problems before you need to start thinking about work-arounds, because it's still in development and nothing is in release or deployment yet!)