javascript - What is the execution order when both sync and async script tags are used? -


tell me if wrong. javascript code execute single thread.

the execution of below javascript code a,b , c, sequentially right.

<script src="a"> .... </script> <script src="b"> .... </script> <script src="c"> .... </script> 

the execution of below code depend upon code , time given each scripts means first 'a' start execute (or 'b', don't know), execution of 'a' stop because time given complete others same chance 'b' , 'c' , 'a' again resume , cycle goes on till execution of each scripts done.

<script async src="a"> .... </script> <script async src="b"> .... </script> <script async src="c"> .... </script> 

but happen when there both synchronous , asynchronous scripts occur below.

<script sync src="a"> .... </script> <script async src="b"> .... </script> <script sync src="c"> .... </script> <script sync src="d"> .... </script> <script async src="e"> .... </script> 

the async attribute merely means script downloaded sometime later , therefore start executing sometime later. <script> tags without attribute downloaded , block rest of page until download , execution finished.

async not mean once script runs, may interrupted @ time , script may start run. cooperative multitasking/cpu scheduling , absolutely not happens here. first async script happens complete downloading run, until done, @ point next script start run if there's any.

so, yes, async not know when script start executing, once does, thing running until relinquishes power (meaning script and/or function exits).


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -