HTML Parsing Algorithm and Memory Structure
Ever wonder what actually happens between the moment your browser receives raw HTML bytes and the moment you see a page? Most of us just load HTML files all day and never think about the machinery ...

Source: DEV Community
Ever wonder what actually happens between the moment your browser receives raw HTML bytes and the moment you see a page? Most of us just load HTML files all day and never think about the machinery underneath. This is the first article in a series where we dig into that machinery. Our end goal is a working HTML parser and static site generator, written from scratch, for the pure joy of understanding how things work. No frameworks, no libraries, just us and the spec! The State Machine The browser uses a state machine to parse HTML. Rather than not building a tree directly, it's reading the HTML character by character and switching between states as it goes. Think of it like a traffic light. The light is always in one state: red, yellow, or green. Based on what happens (timer expires, car approaches), it transitions. The HTML parser works the same way. It's always in a specific state, and the character it reads next determines where it goes. It starts in "data state." As it reads characte