Sha256: 751cfc4cd79669b4289ba7245d6c082d718a23c96bc90667fb5935b372f699a2

Contents?: true

Size: 1.94 KB

Versions: 2

Compression:

Stored size: 1.94 KB

Contents

if(!window['speedGun']) { window.speedGun = {}; };

(function($) {
  if(!$) { return }

  speedGun.sendBrowserInfo = function() {
    var data = {};
    var p = window['performance'];

    data.user_agent = navigator.userAgent;

    if(p['navigation']) {
      data.navigation = {
        type: p.navigation.type,
        redirect_count: p.navigation.redirectCount
      };
    }

    if(p['timing']) {
      var t = p.timing;
      data.timing = {
        navigationStart: t.navigationStart,
        redirectStart: t.redirectStart,
        unloadEventStart: t.unloadEventStart,
        unloadEventEnd: t.unloadEventEnd,
        redirectEnd: t.redirectEnd,
        fetchStart: t.fetchStart,
        domainLookupStart: t.domainLookupStart,
        domainLookupEnd: t.domainLookupEnd,
        connectStart: t.connectStart,
        secureConnectionStart: t.secureConnectionStart,
        connectEnd: t.connectEnd,
        requestStart: t.requestStart,
        responseStart: t.responseStart,
        responseEnd: t.responseEnd,
        domLoading: t.domLoading,
        domInteractive: t.domInteractive,
        domContentLoadedEventStart: t.domContentLoadedEventStart,
        domContentLoadedEventEnd: t.domContentLoadedEventEnd,
        domComplete: t.domComplete,
        loadEventStart: t.loadEventStart,
        loadEventEnd: t.loadEventEnd,
      };
    }

    speedGun.send({ browser: data });
    $('#speed_gun_total').text(
      (t.domContentLoadedEventEnd - t.navigationStart).toString() + 'ms'
    );
  };

  speedGun.send = function(data) {
    $.post(speedGun.endpoint, data, function() {});
  };

  var loadedInterval = setInterval(function() {
    if (performance.timing.loadEventEnd != 0) {
      clearInterval(loadedInterval);

      speedGun.id = $('#speed_gun').data('speed-gun-id');
      speedGun.endpoint = $('#speed_gun').data('speed-gun-endpoint') + "/" + speedGun.id;
      speedGun.sendBrowserInfo()
    }
  }, 100);
})(window['jQuery'] || window['Zepto']);

Version data entries

2 entries across 1 versions & 1 rubygems

Version Path
speed_gun-0.0.1 app/assets/javascripts/browser.js
speed_gun-0.0.1 lib/speed_gun/app/public/browser.js