Last modified: 2014-11-17 10:35:39 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T27860, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 25860 - Optimise jQuery.ready by calling it before </body>
Optimise jQuery.ready by calling it before </body>
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Interface (Other open bugs)
1.17.x
All All
: High enhancement with 2 votes (vote)
: 1.22.0 release
Assigned To: Krinkle
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-11-09 23:00 UTC by Ilmari Karonen
Modified: 2014-11-17 10:35 UTC (History)
7 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Ilmari Karonen 2010-11-09 23:00:31 UTC
Currently, JavaScript callbacks registered using addOnloadHook() from wikibits.js are (normally) executed just after the page content has been completely parsed.  This is achieved by including the following code, returned by Skin::getBottomScripts(), just before the </html> closing tag:

<script type="text/javascript">if (window.runOnloadHook) runOnloadHook();</script>

However, addOnloadHook() is being deprecated in favor of jQuery's $(document).ready().  Callbacks registered using that method normally run as soon as jQuery can determine that the page has been completely parsed.  On browsers supporting it, this is done during the DOMContentLoaded event, which should fire only marginally after the call to runOnloadHook().  However, on IE jQuery relies on the readystatechange event, which fires only at a later stage.  This can delay the execution of callback scripts and degrade the user experience.

A simple solution would be to call $.ready(), which runs the callbacks registered using $(document).ready(), from bottomscripts just like runOnloadHook() is currently called.  This solution is recommended in the comment at http://api.jquery.com/ready/#comment-84865796 which also describes the issue.

In an earlier discussion, some concern had been raised that the DOM might not be completely loaded at that point yet.  I haven't found an authoritative source on that, but I'd like to note that:

1. MediaWiki site/user script authors have been doing extensive DOM manipulation in addOnloadHook() callbacks for many years now.  I'm not aware of anyone ever reporting issues with it.

2. I've been personally testing this by calling addOnloadHook($.ready) from [[commons:User:Ilmari_Karonen/vector.js]] since April.  So far I have experienced no problems with this whatsoever, despite being an active user and script author on that site (although, admittedly, I haven't gone out of my way to conduct extensive cross-browser testing with it).

(Ps. Apparently ResourceLoader moves a lot of JS/CSS that used to go in <head> into bottomscripts.  Presumably the call to $.ready() should occur in a separate <script> element at the very end of the scripts.)
Comment 1 Trevor Parscal 2010-11-10 18:12:46 UTC
I will support this, cautiously, but we need to keep an eye on the lower browsers that we are sending JS to (like IE6 for instance).
Comment 2 db [inactive,noenotif] 2012-11-08 20:07:23 UTC
Is this superseeded by the ResourceLoader?
Comment 3 Krinkle 2012-11-08 21:31:40 UTC
(In reply to comment #2)
> Is this superseeded by the ResourceLoader?

No, it isn't.
Comment 4 db [inactive,noenotif] 2013-05-10 16:22:10 UTC
Maybe related: Gerrit change #61494
Comment 5 Andre Klapper 2013-08-14 14:26:52 UTC
(In reply to comment #4)
> Maybe related: Gerrit change #61494

Bug 34542 and bug 47457 were related to that patch. 

Ilmari / Trevor: Is this still an issue after that Gerrit change got merged in April 2013.
Comment 6 Krinkle 2013-10-25 19:19:50 UTC
Fixed by 0a000d5cf4f915f8.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links