4 ms·
How do browsers parse URLs then?
by axiosgunnar 5y ago
How do browsers parse URLs then?
- djur 5y agoThere's actually a standard for it these days. https://url.spec.whatwg.org/#url-parsing https://url.spec.whatwg.org/#url-parsing
- wolfgang42 5y agoHere’s a polyfill for the JS URL() interface which should give you a taste: https://github.com/zloirock/core-js/blob/272ac1b4515c5cfbf348b069f1da829165a7181e/packages/core-js/modules/web.url.js#L336 https://github.com/zloirock/core-js/blob/272ac1b4515c5cfbf34... (I tried finding the one in Firefox but I couldn’t actually work out where it started, this one is much easier to follow) TLDR: it’s a traditional parser—a big state machine that steps through the URL character by character and tokenizes it into the relevant pieces.