Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two main reasons to put CSS before JavaScript.</p> <ol> <li><p>Old browsers (Internet&nbsp;Explorer 6-7, Firefox 2, etc.) would block all subsequent downloads when they started downloading a script. So if you have <code>a.js</code> followed by <code>b.css</code> they get downloaded sequentially: first a then b. If you have <code>b.css</code> followed by <code>a.js</code> they get downloaded in parallel so the page loads more quickly.</p></li> <li><p>Nothing is rendered until all stylesheets are downloaded - this is true in all browsers. Scripts are different - they block rendering of all DOM elements that are <em>below the script tag</em> in the page. If you put your scripts in the HEAD then it means the entire page is blocked from rendering until all stylesheets and all scripts are downloaded. While it makes sense to block all rendering for stylesheets (so you get the correct styling the first time and avoid the flash of unstyled content FOUC), it doesn't make sense to block rendering of the entire page for scripts. Often scripts don't affect any DOM elements or just a portion of DOM elements. <strong>It's best to load scripts as low in the page as possible, or even better load them asynchronously.</strong></p></li> </ol> <p>It's fun to create examples with <a href="http://cuzillion.com/" rel="noreferrer">Cuzillion</a>. For example, <a href="http://stevesouders.com/cuzillion/?c0=hj1hfff2_0_f" rel="noreferrer">this page</a> has a script in the HEAD so the entire page is blank until it's done downloading. However, if we move the script to the end of the BODY block the page header renders since those DOM elements occur above the SCRIPT tag, as you can see on <a href="http://stevesouders.com/cuzillion/?c0=bj1hfff2_0_f" rel="noreferrer">this page</a>.</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.
    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