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?
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.
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.
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.
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.
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
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With