From 45dacc62b530cd2e3cba6dfcf062f9f08cbb4a26 Mon Sep 17 00:00:00 2001 From: Nic Jansma Date: Thu, 10 Aug 2017 10:23:36 -0400 Subject: [PATCH] SPA: Calculate Front-End / Back-End even if ResTiming isn't enabled but the plugin is available --- plugins/auto-xhr.js | 2 +- plugins/restiming.js | 26 +++++++++++++------ .../05-angular/108-location-change-only.js | 2 +- .../05-angular/113-route-change-abld.js | 2 +- tests/test-templates/spa/00-simple.js | 2 +- tests/test-templates/spa/04-route-change.js | 2 +- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/plugins/auto-xhr.js b/plugins/auto-xhr.js index 23becdc4f..8ba91fcc3 100644 --- a/plugins/auto-xhr.js +++ b/plugins/auto-xhr.js @@ -462,7 +462,7 @@ // Add ResourceTiming data to the beacon, starting at when 'requestStart' // was for this resource. if (BOOMR.plugins.ResourceTiming && - BOOMR.plugins.ResourceTiming.is_supported() && + BOOMR.plugins.ResourceTiming.is_enabled() && resource.timing && resource.timing.requestStart) { var r = BOOMR.plugins.ResourceTiming.getCompressedResourceTiming( diff --git a/plugins/restiming.js b/plugins/restiming.js index af327e9a0..b08eeab05 100644 --- a/plugins/restiming.js +++ b/plugins/restiming.js @@ -1423,7 +1423,7 @@ see: http://www.w3.org/TR/resource-timing/ complete: false, sentNavBeacon: false, initialized: false, - supported: false, + supported: null, xhr_load: function() { if (this.complete) { return; @@ -1490,8 +1490,6 @@ see: http://www.w3.org/TR/resource-timing/ BOOMR.plugins.ResourceTiming = { init: function(config) { - var p = BOOMR.getPerformance(); - BOOMR.utils.pluginConfig(impl, config, "ResourceTiming", ["xssBreakWords", "clearOnBeacon", "urlLimit", "trimUrls", "trackedResourceTypes", "serverTiming"]); @@ -1499,15 +1497,12 @@ see: http://www.w3.org/TR/resource-timing/ return this; } - if (p && - typeof p.getEntriesByType === "function" && - typeof window.PerformanceResourceTiming !== "undefined") { + if (this.is_supported()) { BOOMR.subscribe("page_ready", impl.done, null, impl); BOOMR.subscribe("prerender_to_visible", impl.prerenderToVisible, null, impl); BOOMR.subscribe("xhr_load", impl.xhr_load, null, impl); BOOMR.subscribe("onbeacon", impl.onBeacon, null, impl); BOOMR.subscribe("before_unload", impl.done, null, impl); - impl.supported = true; } else { impl.complete = true; @@ -1520,8 +1515,23 @@ see: http://www.w3.org/TR/resource-timing/ is_complete: function() { return true; }, + is_enabled: function() { + return impl.initialized && this.is_supported(); + }, is_supported: function() { - return impl.initialized && impl.supported; + var p; + + if (impl.supported !== null) { + return impl.supported; + } + + // check for getEntriesByType and the entry type existing + var p = BOOMR.getPerformance(); + impl.supported = p && + typeof p.getEntriesByType === "function" && + typeof window.PerformanceResourceTiming !== "undefined"; + + return impl.supported; }, // // Public Exports diff --git a/tests/page-templates/05-angular/108-location-change-only.js b/tests/page-templates/05-angular/108-location-change-only.js index 62079e1a6..775a14331 100644 --- a/tests/page-templates/05-angular/108-location-change-only.js +++ b/tests/page-templates/05-angular/108-location-change-only.js @@ -86,7 +86,7 @@ describe("e2e/05-angular/108-location-change-only", function() { if (window.MutationObserver && typeof BOOMR.plugins.RT.navigationStart() !== "undefined") { var pt = window.performance.timing; var b = tf.beacons[0]; - assert.equal(b.t_resp, pt.responseStart - pt.fetchStart); + assert.equal(b.t_resp, pt.responseStart - pt.navigationStart); } }); diff --git a/tests/page-templates/05-angular/113-route-change-abld.js b/tests/page-templates/05-angular/113-route-change-abld.js index e91d49e11..f8267081d 100644 --- a/tests/page-templates/05-angular/113-route-change-abld.js +++ b/tests/page-templates/05-angular/113-route-change-abld.js @@ -82,7 +82,7 @@ describe("e2e/05-angular/113-route-change-abld", function() { if (window.MutationObserver && typeof BOOMR.plugins.RT.navigationStart() !== "undefined") { var pt = window.performance.timing; var b = tf.beacons[0]; - assert.equal(b.t_resp, pt.responseStart - pt.fetchStart); + assert.equal(b.t_resp, pt.responseStart - pt.navigationStart); } }); diff --git a/tests/test-templates/spa/00-simple.js b/tests/test-templates/spa/00-simple.js index cdb577b32..40d48fd8d 100644 --- a/tests/test-templates/spa/00-simple.js +++ b/tests/test-templates/spa/00-simple.js @@ -24,7 +24,7 @@ BOOMR_test.templates.SPA["00-simple"] = function() { if (window.MutationObserver && typeof BOOMR.plugins.RT.navigationStart() !== "undefined") { var pt = window.performance.timing; var b = tf.lastBeacon(); - assert.equal(b.t_resp, pt.responseStart - pt.fetchStart); + assert.equal(b.t_resp, pt.responseStart - pt.navigationStart); } }); diff --git a/tests/test-templates/spa/04-route-change.js b/tests/test-templates/spa/04-route-change.js index b650dcb77..869ddc0f9 100644 --- a/tests/test-templates/spa/04-route-change.js +++ b/tests/test-templates/spa/04-route-change.js @@ -87,7 +87,7 @@ BOOMR_test.templates.SPA["04-route-change"] = function() { if (window.MutationObserver && typeof BOOMR.plugins.RT.navigationStart() !== "undefined") { var pt = window.performance.timing; var b = tf.beacons[0]; - assert.equal(b.t_resp, pt.responseStart - pt.fetchStart); + assert.equal(b.t_resp, pt.responseStart - pt.navigationStart); } });