I can point you to exactly what you are looking for. It is an RFC document so you have to sift through a lot of noise to get to what you want but this is a legit feature (not a hack) of supposed http clients.
b) If the embedded URL starts with a scheme name, it is
interpreted as an absolute URL and we are done.
c) Otherwise, the embedded URL inherits the scheme of
the base URL.
Read more: http://www.faqs.org/rfcs/rfc1808.html (search for the heading "Resolving Relative URLs" and see steps 1 and 2 below) or here: http://freesoft.org/CIE/RFC/1808/18.htm
As an FYI, I use this in pretty much all of my production projects -- not just for JS resources, but for links to other resources such as images and CSS. Works pretty much everywhere. I've tried this in IE, FF, Opera, Chrome, Safari/Webkit all going back multiple previous versions (where applicable).
Examples:
- < img src="//static.example.com/img/token.png" />
- < link rel="stylesheet" type="text/css" href="//static.example.com/css/screen.css" media="screen" />
- < script type="text/javascript" src="//static.example.com/js/jquery.js">
If find this method to be cleaner than writing code to figure out if we are on http/https.