Order in which component files are parsed
When browsers send requests to servers for HTML files, those HTML files often contain <link> elements referencing external CSS stylesheets and <script> elements referencing external JavaScript scripts. It’s important to know the order in which those files are parsed by the browser as the browser loads the page:
- The browser parses the HTML file first, and that leads to the browser recognizing any
<link>
-element references to external CSS stylesheets and any<script>
-element references to scripts. - As the browser parses the HTML, it sends requests back to the server for any CSS files it has found from
<link>
elements, and any JavaScript files it has found from<script>
elements, and from those, then parses the CSS and JavaScript. - The browser generates an in-memory DOM tree from the parsed HTML, generates an in-memory CSSOM structure from the parsed CSS, and compiles and executes the parsed JavaScript.
- As the browser builds the DOM tree and applies the styles from the CSSOM tree and executes the JavaScript, a visual representation of the page is painted to the screen, and the user sees the page content and can begin to interact with it.
转:https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/How_the_Web_works