Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>None of the selectors are optimized for speed or cached. As jQuery goes, I've seen worse and it will probably work fine. As high-performance, professional JavaScript goes, it gets a D-.</p> <pre><code>//side comments are not really there in prod code, this is just for example purposes //this code assumes the DOM nodes in main wrapper have no ids and can not get them, obviously ids make a huge difference $(function () { //make sure the document is ready, not needed if you place in &lt;script&gt; at the bottom //single var statement validates JSLint "use strict"; var doc = document, main = doc.getElementById("main"), //faster than sizzle $main = $(main), //faster instantiation of jQuery $wrapper = $main.children(".wrapper"), //faster than find, use if possible $nav = $(".nav"), //cached html; //initialize $wrapper.hide(); html = $nav.children(".selected").eq(0).html().toLowerCase(); //stop on first $(doc.getElementById(html)).show(); //add handler $nav.delegate("a", "click", function () { //delegate outperforms multiple handlers var $this = $(this); //cached if ($this.is(".selected")) { return false; //return early if this is already selected } $this.siblings(".selected").eq(0).removeClass("selected"); //you shouldn't need to find more than one $this.addClass("selected"); $wrapper.hide(); //TODO add ids $(doc.getElementById($this.html().toLowerCase())).show(); return false; }); }); </code></pre> <p>If you want to work on your performance, get very familiar with the work of Nick Zackas and other performance gurus who do presentations and write books on the subject. Rely as little as possible on jQuery. Use JSPerf religiously. Question everything you write and leave comments when you're unsure or think it can be done better in future implementations.</p> <p>Good luck to you, the results are worth the journey.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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