protocol-relative URL (v2)

Revision 2 of this benchmark created on


Description

The idea of browsers supporting protocol relative URLs (e.g. <img src="//domain.com/img/logo.png">) 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') + '.google-analytics.com/ga.js'

or as I have in the past:

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

This topic has been discussed at length by Paul Irish: http://paulirish.com/2010/the-protocol-relative-url/

and the creator of jsperf, Mathias Bynens: http://mathiasbynens.be/notes/async-analytics-snippet


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
TestOps/sec
Direct Link Control
var foo=bar;
ready
Ternary Test
var foo=bar;
ready
Protocol Relative Test
test 3
ready

Revisions

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