Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can protocol be omitted from absolute paths on a webpage?

Tags:

url

I recently ran across a website that had some interesting styling on a select element. I went to investigate and found this (names changed to protect the innocent):

<script type="text/javascript" src="//www.domain.tld/file.js"></script>

It works despite HTTP: being omitted. What is the purpose of leaving off the protocol?

like image 972
mwcz Avatar asked Jan 07 '10 04:01

mwcz


People also ask

Why absolute referencing must be avoided in referencing a file in a webpage?

Absolute paths are inflexible and do not automatically adjust to the content on the page or changes. Moreover, absolute links are always unique. A single page, document, or directory on the web are all opened using only one absolute path.

Can you omit http when entering URL?

I just learned from a colleague that omitting the "http | https" part of a URL in a link will make that URL use whatever scheme the page it's on uses. That link will go to http://www.google.com.

Can links in HTML have non HTML protocols?

They support all the protocols supported by browsers- ftp, mailto, file etc. Also, you can preceed URL name with '#', to link to a html id internally in the page. You can give just the name or directory path, without a protocol, which will be taken as a relative URL.

What is difference between absolute and relative URL?

An absolute URL contains all the information necessary to locate a resource. A relative URL locates a resource using an absolute URL as a starting point. In effect, the "complete URL" of the target is specified by concatenating the absolute and relative URLs.


2 Answers

It will use the protocol you're already using. Useful for sites with both https and http versions.

So if you're on https://www.domain.tld/file.js the script will be https://www.domain.tld/file.js.

If you're on http://www.domain.tld/ the script will be http://www.domain.tld/file.js.

like image 70
Brian McKenna Avatar answered Oct 10 '22 02:10

Brian McKenna


i believe this is short hand for a relative path to the protocol. So it should use the same protocol as is being used for that session. e.g if you grabbed that page with http, then this url is relative to http protocol

like image 44
D.C. Avatar answered Oct 10 '22 03:10

D.C.