Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've been looking for similar answers and was about to post a question when I found <a href="https://stackoverflow.com/questions/5035741/how-do-i-load-a-variable-number-of-scripts-with-jquery-getscript-before-running">this stackoverflow question</a> -- and yours.</p> <p>So here is what I've found out:</p> <ul> <li>The script <code>defer</code> approach <em>hints</em> to a browser to wait until the document has finished loading before executing the script. BUT it still loads the script first (assuming that they're located in the HEAD of the document).</li> <li>jQuery has a <code>.getScript()</code> method which can be used to load any number of scripts whenever and wherever needed. You could even apply it to an <code>onClick</code> event on a link for instance!</li> <li>There are also several libraries aimed at dynamic, non-blocking loading such as <a href="http://labjs.com/" rel="nofollow noreferrer">LABjs</a>, <a href="http://requirejs.org/" rel="nofollow noreferrer">RequireJS</a> or <a href="http://headjs.com/" rel="nofollow noreferrer">HEADjs</a>.</li> </ul> <p>I guess it's up to you which approach you choose, if you're only on a small project and are already using and/or used to using jQuery then I'd go with that. Otherwise maybe check out one of the libraries.</p> <p>Just to state again however that as best as I can tell <code>DEFER</code> will not prevent page blocking when loading scripts. But a typical and very simple solution to this is to include all your scripts in the page footer rather than the HEAD.</p> <p><br/> People please feel free to correct me if I'm wrong on any of the above! -- Thanks</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.
    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