Google Analytics protocol check versus hardcoded string (v3)

Revision 3 of this benchmark created 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
var url = ('https:' == location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
ready
ternary best
var url = ('https:' == location.protocol ? 'https://ssl.google-analytics.com/ga.js' : 'http://www.google-analytics.com/ga.js');
ready
hardcoded string
var url = '//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