Why are HTML files parsed and not just read in the browser?
Why are HTML files parsed and not just read in the browser? What is the order of operation inside a browser? Let us answer the front-end lead-level interview questions.
Why are HTML files parsed and not just read in the browser?
"Reading a file" in software engineering means you are loading the contents of the file into the memory or buffer. No meaningful operation is performed on the reading of a file.
The browsers parse the HTML to understand the structure of the file and perform operations on it like loading the assets like CSS, JS scripts, etc.
What is the order of operation inside a browser?
-
HTML is parsed
-
External stylesheets are loaded. Assuming that the link tags are in the head section of the document. In sites built with AMP, we do not have external CSS.
-
Scripts are executed as they are parsed in the document. Here the assumption is that the scripts do not async, defer attributes, and are placed below the link tag in the head section.
-
HTML DOM is fully constructed. In this step, the DOMContentLoaded event gets fired.
-
Images and external content are loaded.
-
The page is finished loading. In this step, the load event gets fired.