protocol-relative URL (v2)

Revision 2 of this benchmark created on


The idea of browsers supporting protocol relative URLs (e.g. <img src="//">) is intriguing for linking to an external assets like JS and images when a site could be optionally loaded in an SSL or clear-text session. I wanted to test a wide variety of browsers for support of this method and any impact on load times this might have in comparison to traditional methods of client-side solutions.

Traditional methods of solving this problem on the client side require all assets to be on the same server (e.g. <img src="/img/logo.png">) or require a modification of the protocol with Javascript via an if/then or ternary test.

Google Analytics handles this via a JS ternary test:

ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + ''

or as I have in the past:

document.write('\x3Cscript src="'+document.location.protocol+'//"\x3E\x3C/script\x3E');}

This topic has been discussed at length by Paul Irish:

and the creator of jsperf, Mathias Bynens:

I am going to test loading a JS & IMG files via various methods and test for their success.

Test runner

Ready to run.

Testing in
Direct Link Control
var foo=bar;
Ternary Test
var foo=bar;
Protocol Relative Test
test 3


You can edit these tests or add more tests to this page by appending /edit to the URL.