Google Analytics protocol check versus hardcoded string

Benchmark created by Mathias Bynens 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 ? '//ssl' : '//www') + '.google-analytics.com/ga.js';
ready
Hardcoded string
'http://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