Are external links linked to javascript so the browser waits for them to load?

When your page is parsed, and it meets <script src='someExternalSite/jquery.js'></script>or something else, does the page wait before this file is loaded and accessible before continuing with the parsing?

Added:

Most browsers load all scripts at the same time to save time (even if they run in order)?

+5
source share
5 answers

each tag blocks the page from further rendering until the js file is fully loaded. It’s a good idea to place the js file at the end of the body tag

+2
source

, ?

JS, , . , , .

, ( )?

, , . - , , .

+2

, , script .

.

<script src='someExternalSite/script1.js'></script>
<script src='someExternalSite/script2.js'></script>

. script2.js script1.js, , .

. .

document.write() , script (script1.js script2.js):

   document.write('<script src=\'someExternalSite/script1.js\'></script>');
   document.write('<script src=\'someExternalSite/script2.js\'></script>');

, , :

var script1 = document.createElement('script');
script1.src = 'script1.js';
document.getElementByTagName('body')[0].appendChild(script1);    

var script2 = document.createElement('script');
script2.src = 'script2.js';
document.getElementByTagName('body')[0].appendChild(script2);    

, , getcha. , Webkit, , script2.js 1.js, . , , javascript, .

script?

+2

All major browsers should try to get these files synchronously, because the next script in the list may rely on one of them earlier.

0
source

Yes, that’s why people recommend adding scripts immediately before the tag </body>or using the attribute defer.

0
source

All Articles