Skip to content

Commit

Permalink
SPA: Calculate Front-End / Back-End even if ResTiming isn't enabled b…
Browse files Browse the repository at this point in the history
…ut the plugin is available
  • Loading branch information
nicjansma committed Apr 4, 2018
1 parent e70b3f1 commit 45dacc6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion plugins/auto-xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
26 changes: 18 additions & 8 deletions plugins/restiming.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1490,24 +1490,19 @@ 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"]);

if (impl.initialized) {
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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/page-templates/05-angular/113-route-change-abld.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/test-templates/spa/00-simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/test-templates/spa/04-route-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down

0 comments on commit 45dacc6

Please sign in to comment.