lib/speed_gun/app/public/browser.js in speed_gun-0.0.1 vs lib/speed_gun/app/public/browser.js in speed_gun-0.0.2
- old
+ new
@@ -48,18 +48,32 @@
(t.domContentLoadedEventEnd - t.navigationStart).toString() + 'ms'
);
};
speedGun.send = function(data) {
- $.post(speedGun.endpoint, data, function() {});
+ if(speedGun.activated) {
+ $.post(speedGun.endpoint, data, function() {});
+ } else {
+ if(!speedGun.queue) { speedGun.queue = [] };
+ speedGun.queue.push(data);
+ }
};
+ speedGun.processQueue = function() {
+ var queue = speedGun.queue || [];
+ for(var i = 0; i < queue.length; i++) {
+ speedGun.send(queue[i])
+ }
+ }
+
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()
+ speedGun.activated = true;
+ speedGun.sendBrowserInfo();
+ speedGun.processQueue();
}
}, 100);
})(window['jQuery'] || window['Zepto']);