-
Notifications
You must be signed in to change notification settings - Fork 22.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
URL.parse() static method docs #33207
Conversation
Preview URLs
External URLs (2)URL:
URL:
(comment last updated: 2024-05-07 00:03:38) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the big comment here which is probably out of scope for this PR is that we should have a definitive separate guide to "resolving relative URLs" that we can point to from all the places that do this.
@wbamberg All ready for another review. Includes new doc for Resolving URLs. |
Thank you for writing this! I think relative URL resolution is quite an important thing that AFAIK is documented nowhere on MDN. The nearest thing is https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/What_is_a_URL which doesn't do into enough detail. But I have a couple of high level comments on this. First, I think it's better to present this as a generic algorithm - "how browsers handle relative URLs" - rather than specifically as a feature of the Second, I like that you have lots of examples and I appreciate explaining it in a fairly informal way. But it would be great if we could also present it in a more rigorous/precise way. The trick is to explain https://datatracker.ietf.org/doc/html/rfc3986.html#section-5.2 in a way that is more comprehensible but just as precise. I've had a shot at writing this up below, perhaps we could work out some version of this? What do you think? We could present URL resolution as a three-step process:
Split URLsFirst, split base and relative URLs into their components (we already define the components in https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/What_is_a_URL):
Calculate component values
Merging base and relative paths
(I'm not sure if we can assume that base must have an authority, and therefore simplify this a bit?) Remove dotsThis is the process of removing "./" characters and processing "../" to remove parents. This is quite hard to explain precisely... Compose componentsFinally we combine the components to produce a single URL:
Again, can we assume that scheme and authority are required for HTTPS URLs, so as to simplify the explanation? |
My concern here is that I want to get docs for So if we agree this is the right place for the doc and that the doc is "better than what was there before", then I suggest I rename to "how browsers handle relative URLs" and you merge as is. Then I come back to this after the release (or you can hack at it given you clearly have a better idea of this than me) |
Yes, there are a number of other cases too, like a relative URL of "//example.org", which is scheme-relative, or a relative URL of "this/../that" which eats its own parent, not the parent of the base, or URLs with queries and fragments.
I did think about this, but the preamble for the URL API says "The URL API is a component of the URL standard, which defines what constitutes a valid Uniform Resource Locator and the API that accesses and manipulates URLs." which makes it seem like a good enough place. And there really isn't anywhere else except Learn, and I think that is wrong (the algorithm is not learning content).
That's fair. I wasn't actually expecting you to add this guide at all, as it is fairly tangential to your original PR.
I don't, really, I just spent a bit of time trying to understand the RFC. But there is definitely still work to do to make sure it is correct and complete. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
TBH I didn't put a lot of time into reviewing the guide, since if it will get rewritten anyway there didn't seem like much point.
It seems like the spec deprecates the whole "relative URL" terminology:
(https://datatracker.ietf.org/doc/html/rfc3986.html#section-1.2.3) |
Co-authored-by: wbamberg <[email protected]>
Thanks @wbamberg I have
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 thank you @hamishwillee !
* URL.parse() static method docs * Apply suggestions from code review - easy ones Co-authored-by: wbamberg <[email protected]> * Fix up url and following note to be less repetitive * Remove example description from log * Resolved, not appended * Base URL resolution is more complicated than appending * Update files/en-us/web/api/url/parse_static/index.md Co-authored-by: Denis Pushkarev <[email protected]> * Add resolving relative URLs * Correct parse/url const * Update resolving relative URLs * Remove some no longer needed examples * Apply suggestions from code review Co-authored-by: wbamberg <[email protected]> * Apply suggestions from code review * Move resolving topic and refer to relative references --------- Co-authored-by: wbamberg <[email protected]> Co-authored-by: Denis Pushkarev <[email protected]>
FF126 supports the
URL.parse
static method. This is just like the URL constructor except that it doesn't throw if the parameter strings define an invalid URL.This adds a page with a live example, and does some fixes and cross linking to the
URL
constructor.Related docs work can be tracked in #33080