Breakdown of Web Page Loading and Execution Question: What is the sequence of loading and execution of a web page? Answer: 1. HTML Parsing: Browser downloads and parses the HTML document, creating the Document Object Model (DOM). 2. Resource Loading: External resources are downloaded in parallel: JavaScript (external scripts) CSS (external style sheets) Images 3. JavaScript Execution: Inline JavaScript in tags is executed.</li> <li>External JavaScript files are parsed and executed when downloaded.</li> </ul> <p><strong>4. CSS Execution:</strong></p> <ul> <li>External CSS files are downloaded and parsed.</li> <li>CSS rules are applied to the DOM elements.</li> </ul> <p><strong>5. DOM Modifications:</strong></p> <ul> <li>$(document).ready() event fires when the DOM is ready (all resources loaded).</li> <li>Internal JavaScript (within <script> tags) executes, potentially modifying the DOM.</li> </ul> <p><strong>6. Resource Display:</strong></p> <ul><li>Images and other external resources are displayed on the web page.</li></ul> <p><strong>7. Additional JavaScript Execution:</strong></p> <ul><li>External JavaScript files loaded after DOM is ready continue to execute.</li></ul> <p><strong>Image Download:</strong></p> <ul> <li>Both abc.jpg and kkk.png will be downloaded.</li> <li>The image displayed in the <img> element will be kkk.png, as its src attribute is updated by the JavaScript code.</li> </ul> <p><strong>Browser Execution Flow:</strong></p> <p>The sequence of loading and execution may vary slightly between browsers, but the general flow outlined above remains consistent.</p> <p><strong>Parallelism:</strong></p> <p>Some resources, such as CSS and images, can be loaded in parallel without blocking the parsing of HTML. However, external JavaScript files block the parsing of HTML until they are downloaded and executed.</p> <p><strong>Reference:</strong></p> <ul> <li>[Browser Engineering: Load and Execution of a Web Page](https://browser.engineering/posts/load-execute-web-page/)</li> <li>[Google Developers: JavaScript Execution Order](https://developers.google.com/web/fundamentals/primers/html-and-css/script-execution)</li> </ul>