Skip to content

Instantly share code, notes, and snippets.

@dmail
Last active June 9, 2026 23:37
Show Gist options
  • Select an option

  • Save dmail/54677cc3eae1661813e3a87840666f83 to your computer and use it in GitHub Desktop.

Select an option

Save dmail/54677cc3eae1661813e3a87840666f83 to your computer and use it in GitHub Desktop.
URL parts naming. Inspired from web browsers API (new URL(), window.location) and rfc3986.
/*
href
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
origin โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ authority โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ host resource
โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ โ”‚ hostname โ”‚ pathname โ”‚ โ”‚
โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚
protocol userinfo subdomain domain โ”‚ โ”‚ filename โ”‚ โ”‚
โ”Œโ”€โ”ดโ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ” โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚
scheme โ”‚username password lowerleveldomains secondleveldomain topleveldomain port dirname basename extension search hash
โ”Œโ”€โ”€โ”ดโ”€โ”€โ”€โ”โ”‚โ”Œโ”€โ”€โ”ดโ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”ดโ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”ฌโ”€โ”ฌโ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”โ”Œโ”€โ”ดโ”โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”โ”Œโ”€โ”€โ”ดโ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ” โ”Œโ”ดโ”
โ”‚ โ”‚โ”‚โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚โ”‚ โ”‚ โ”‚ โ”‚โ”‚ โ”‚โ”‚ โ”‚โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
scheme://username:password@test.abcdedgh.www.secondleveldomain.topleveldomain:1234/hello/world/basename.extension?name=ferret#hash
*/
@tamanobi

tamanobi commented Jul 31, 2022

Copy link
Copy Markdown

Great post! Thanks ๐Ÿ˜„

nits:
s/ressource/resource/

@dmail

dmail commented Jul 31, 2022

Copy link
Copy Markdown
Author

My pleasure, what do you mean by "s/ressource/ressource" ?

@papinianus

Copy link
Copy Markdown

It looks The s command of sed because not like in french, it is expected that there will be a single s in spelling of the word resource.

Thanks for your great post!

@dmail

dmail commented Jul 31, 2022

Copy link
Copy Markdown
Author

Thank you I'll update shortly

@tamanobi

Copy link
Copy Markdown

Thank you.

@tamanobi

tamanobi commented Aug 1, 2022

Copy link
Copy Markdown

@dmail
I found two errors in your document. I would like you to correct it as it is a very informative document.

The two in the diagram are "search" and "hash". These are defined as Query and Fragment in rfc3986.

Your post has been found by Japanese speakers and is being well-received on Twitter as "easy to understand".
Ref: https://twitter.com/bokken_/status/1553608887739109376?s=20&t=xEvBqi4cGu9-bWu53-i_2g

Once again, thank you for your excellent post.

Translated with www.DeepL.com/Translator (free version)

@tamanobi

tamanobi commented Aug 1, 2022

Copy link
Copy Markdown

@dmail Sorry, your document is based on "Location" and not on URL. Please ignore my point.
https://developer.mozilla.org/ja/docs/Web/API/Location

@dmail

dmail commented Aug 1, 2022

Copy link
Copy Markdown
Author

nits:
s/ressource/resource/

It's updated ๐Ÿ‘

@dmail Sorry, your document is based on "Location" and not on URL. Please ignore my point.

I have added "Inspired from web browsers API (new URL(), window.location) and rfc3986." to the description ๐Ÿ‘

@dmail

dmail commented Aug 1, 2022

Copy link
Copy Markdown
Author

A more detailed description about this gist.

I have created this gist to list and identify all urls parts.
The names are meant to name JavaScript variables or identify what a JavaScript variable refers to.
For this reason names are coming first from URL Web API. Then all blanks left by URL web API are filled using rfc3986.

It results in the 2 differences mentioned in gistcomment-4251501

  • "search" from web APIs is favored over "query" from rfc3986
  • "hash" from web APIs is favored over "fragment" from rfc3986

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment