Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just because <code>jQuery.ready()</code> executes does not mean that the page is visible to the end user. This is a behaviour defined by browsers and these days there are really 2 events to take into consideration here as mootools puts it <code>DomReady</code> vs <code>Load</code>. When jQuery executes the <code>ready</code> method it's talking about the dom loading loaded however this doesn't mean the page is ready to be viewed by the user, external elements which as pictures and even style sheets etc may still be loading.</p> <p>Any binding you do, even extremely inefficient ones will bind a lot faster than all the external resources being loaded by the browser so IMHO user should experience no difference between the page being displayed and functionality being made available.</p> <p>As for finding binding on elements in your DOM. You are really just fearing that things will get lost. This has not really been my actual experience, more often than not in your JS you can check what page you are on and only add javascript for that page (as Aadit mentioned above). After that a quick find operation in your editor should help you find anything if stuff gets lost.</p> <p>Keep in mind that under true MVC the functionality has to be separate from the presentation layer. This is exactly what OO javascript or unobtrusive javascript is about. You should be able to change your DOM without breaking the functionality of the page. Yes, if you change the css class and or element id on which you bind your JS will break, however the user will have no idea of this and the page will at least appear to work. However if this is a big concern you can use OO-Javascript and put <code>div</code>'s or <code>span</code>'s as placeholders in your dom and use these as markers to insert functionality or tell you that it exists, you can even use html comments. However, in my experience you know the behavior of your site and hence will always know that there is some JS there.</p> <p>While I understand most of your concerns about useless traversals, I do think you are nickle and dime'ing it at this point if you are worried about 1 additional traversal. <em>Previous to IE8 it used to be the case that traversing with the tag name and id was a lot faster than my selector but this is no longer true infact browsers have evolved to be much faster when using just the selectors</em>:</p> <ul> <li><p><code>$("a#myLink")</code> - slowest.</p></li> <li><p><code>$("a.myLink")</code> - faster.</p></li> <li><p><code>$("#Link")</code> - fastest.</p></li> <li><p><code>$(".myLink")</code> - fastest.</p></li> </ul> <p>In the link below you can see that as many as 34 thousand operations per second are being performed so I doubt speed is an issue.</p> <p>You can use firebug to test the speed of each in the case of a very large dom.</p> <p>In Summary:</p> <p>a) Don't worry about losing js code there is always <code>ctrl+f</code></p> <p>b) There is no lag because dom ready does not mean the page is visible to start with.</p> <p><strong>Update</strong> Fixed order of speed in operations based on the tests results from <a href="http://jsperf.com/jquery-selector-speed-tests" rel="nofollow">here</a> However keep in mind that performances of IE &lt; 8 are really had if you don't specify the container (this used to be the rule, now it seems to be the exception to the rule).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload