ImmutableURLinterface
{
readonly href: URLString;
readonly origin: URLString;
readonly pathname: AbsolutePath;
}| Property | Type | |
|---|---|---|
.href | URLString | A URL string has a protocol and a //. required readonly |
.origin | URLString | A URL string has a protocol and a //. required readonly |
.pathname | AbsolutePath | Absolute path string starting with a / slash. required readonly |
Object that describes a valid URL, e.g. http://example.com/path/to/resource
- Improves the builtin Javascript
URLclass to more accurately type its properties.
URI and URL differences:
- According to RFC 3986, URLs are a subset of URIs that have a hierarchical path component, e.g.
http://example.com/path. - The
//at the start of a URL indicates that it has a hierarchical path component, so this makes it a URL. - The absence of
//indicates a non-hierarchical URI. - URLs can be considered as "hierarchical URIs".
- All URLs are also URIs, but not all URIs are URLs.
Javascript URL problems:
- Javascript
URLinstance can actually represent any kind of URI (not just URLs). - It's more "correct" terminology to use
URIto refer to what the JavascriptURLclass represents. - You can tell the difference because a URL will have a non-empty
hostproperty, whereas URIs will never have ahost(it will be""empty string). - Javascript URLs are mutable which can lead to subtle bugs.