Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>By modern "best practice", it's like this:</p> <ul> <li>Put scripts in the <code>&lt;head&gt;</code> when they should happen before the page starts being rendered. Examples are things like HTML 5 shim libraries or Modernizr.</li> <li>Put scripts in "ready" handlers when there's limited control over how the script is imported. Things like utilities that can be included on a page to unobtrusively add features generally use "ready" handlers because they can't be sure of how they'll be used.</li> <li>Put scripts at the end of the <code>&lt;body&gt;</code> if you can get away with it in all other cases.</li> </ul> <p>Sometimes you end up with dependencies in pages that require things that you'd otherwise like to load at the end of the body element. That's an undesirable situation, but if you can't avoid it that can force scripts to be loaded in the <code>&lt;head&gt;</code> instead of at the end of the <code>&lt;body&gt;</code>.</p> <p>It's good to load things at the end of the document because browsers evaluate the contents of <code>&lt;script&gt;</code> tags when they load them. (There are some "modern" ways to avoid this, but that's getting into more complicated territory.)</p> <p>The decision of when to use "ready" handlers (or "load" handlers, for that matter) is a little different than the decision about where to put the <code>&lt;script&gt;</code> tag. If you've got intra-page widgets from a server-side template system that generate (undesirable, but what can you do?) jQuery references for example, then you need to import jQuery at the top of the page, even though other code may defer initialization to "ready" handlers. That is to say, the decision about when to use "ready" has to do with whether your script is willing to rely on being imported into a page at the right point, or if it wants to ensure that the right thing happens regardless of where its <code>&lt;script&gt;</code> tag is placed.</p>
    singulars
    1. This table or related slice is empty.
    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.
    3. VO
      singulars
      1. This table or related slice is empty.
    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