javascript - Is there a specification of script execution order when using iframes? -


it's known , understood browsers execute <script> elements in order presented within source of page (barring defer , async etc). i've not been able establish if there specification guarantees order across <iframe> elements also.

if main page contains:

<html>   <head>     <script src="a.js"></script>   </head>   <body>     <iframe src="inner.html" />     <!-- ... -->   </body> </html> 

with inner.html being:

<html>   <head>     <script src="b.js"></script>   </head>   <body>     <!-- ... -->   </body> </html> 

is defined in specification a.js execute before b.js?

what if main page looks this:

<html>   <head>     <script src="a.js"></script>   </head>   <body>     <iframe src="inner.html" />     <!-- ... -->     <script src="c.js"></script>   </body> </html> 

what guaranteed order of execution here, if there one? a.js takes long time load - it's guaranteed still run before c.js. if inner.html , it's resources (including b.js) have loaded before a.js - there in html spec says b.js will not run before a.js? if loads in timely manner, defined in spec somewhere whether b.js should execute before or after c.js?

the best i've managed find far the <iframe> spec is:

when document in iframe marked loaded, user agent must run iframe load event steps in parallel.

however seems (when dig "iframe load event steps") load event dispatched in , amongst other things running on main page, doesn't when inner page parsed , content loaded , (critically) when scripts run within it.

the specification of script element seems clear me:

there 3 possible modes can selected using these attributes. if async attribute present, script executed available, without blocking further parsing of page. if async attribute not present defer attribute present, script executed when page has finished parsing. if neither attribute present, script fetched , executed immediately, before user agent continues parsing page.

(emphasis added.)

you ask:

say a.js takes long time load - it's guaranteed still run before c.js. if inner.html , it's resources (including b.js) have loaded before a.js - there in html spec says b.js not run before a.js?

yes, section quoted above implies b.js won't run before a.js. per specification, parsing stop while a.js fetched , executed. processing of iframe not going happen until after parsing resume, means b.js cannot run before a.js.

c.js execute before b.js. there no single neat paragraph can point @ justify though. explanation spread throughout specification. happens iframe triggers navigation url passed in src. (in spec expressed "navigate element's child browsing context url." navigation described here.) navigation event cause fetch happen. (fetch described here.) , fetches executed in parallel default. script element src fetches data (without async or defer) also stops parsing while fetching happens.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -