Google Analytics protocol check versus hardcoded string (v2)

Revision 2 of this benchmark created by John-David Dalton on


Description

The snippets I’m comparing here aren’t quite the same, but for HTTP-only websites it doesn’t make a difference. See the “Use the protocol check only when it’s needed” section in my article on optimizing the asynchronous Google Analytics snippet for more information.

Setup

var location = window.location;

Test runner

Ready to run.

Testing in
TestOps/sec
Ternary protocol check
('https:' == location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
ready
ternary best
('https:' == location.protocol ? 'https://ssl.google-analytics.com/ga.js' : 'http://www.google-analytics.com/ga.js');
ready
hardcoded string
'//www.google-analytics.com/ga.js';
ready

Revisions

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

  • Revision 1: published by Mathias Bynens on
  • Revision 2: published by John-David Dalton on
  • Revision 3: published on