Vivek V Dwivedi
Vivek V Dwivedi

Reputation: 2615

Is a protocol (eg. http or https) required for a URL to be valid?

Recently I came across a lot of code from analytics plugins where they specify the URL as //fonts.googleapis.com or //www.google.com.

Basically it starts with two forward slashes and then the domain or subdomain. These links work fine in browsers. I have read the following documents, but I am still not sure if above can be called valid URLs (basically should these be reported as broken URLs or not).

https://developer.mozilla.org/en-US/docs/Web/API/URL and https://url.spec.whatwg.org/

Is there a standard specification that I can refer to?

Upvotes: 2

Views: 924

Answers (1)

Alohci
Alohci

Reputation: 82986

They're both valid scheme-relative-URL strings, although they need to be in the context of a Base URL to be meaningful. When used within a web page, the web page will provide the Base URL context.

Although there are other, earlier standards for URLs, the whatwg document represents the most up-to-date, web compatible definition.

Upvotes: 1

Related Questions