Skip to content

Instantly share code, notes, and snippets.

@querymetrics
Created April 10, 2018 14:34
Show Gist options
  • Save querymetrics/7940da0ca577f07dec918a2ee1c72bc0 to your computer and use it in GitHub Desktop.
Save querymetrics/7940da0ca577f07dec918a2ee1c72bc0 to your computer and use it in GitHub Desktop.
WIP auto-xhr patch
diff --git a/plugins/auto-xhr.js b/plugins/auto-xhr.js
index 78a9defa..d495cb21 100644
--- a/plugins/auto-xhr.js
+++ b/plugins/auto-xhr.js
@@ -1028,16 +1028,23 @@
if (node.nodeName.toUpperCase().match(/^(IMG|SCRIPT|IFRAME|IMAGE)$/) ||
(node.nodeName === "LINK" && node.rel && node.rel.match(/\<stylesheet\>/i))) {
- // if the attribute change affected the src/currentSrc attributes we want to know that
- // as that means we need to fetch a new Resource from the server
- if (node._bmr && typeof node._bmr.res === "number" && node._bmr.end[node._bmr.res]) {
- exisitingNodeSrcUrlChanged = true;
- }
-
// we put xlink:href before href because node.href works for <SVG:IMAGE> elements,
// but does not return a string
url = node.src || node.getAttribute("xlink:href") || node.href;
+ // no URL or javascript: or about: or data: URL, so no network activity
+ if (!url || url.match(/^(about:|javascript:|data:)/i)) {
+ return false;
+ }
+
+ // we get called from src/href attribute changes but also from nodes being added
+ // which may or may not have been seen here before.
+ // Check that if we've seen this node before, that the src/href in this case is
+ // different which means we need to fetch a new Resource from the server
+ if (node._bmr && node._bmr.url !== url) {
+ exisitingNodeSrcUrlChanged = true;
+ }
+
if (node.nodeName === "IMG") {
if (node.naturalWidth && !exisitingNodeSrcUrlChanged) {
// img already loaded
@@ -1049,11 +1056,6 @@
}
}
- // no URL or javascript: or about: or data: URL, so no network activity
- if (!url || url.match(/^(about:|javascript:|data:)/i)) {
- return false;
- }
-
current_event = this.pending_events[index];
if (!current_event) {
@@ -1118,6 +1120,7 @@
node._bmr.res = resourceNum;
node._bmr.idx = index;
delete node._bmr.end[resourceNum];
+ node._bmr.url = url;
node.addEventListener("load", function(ev) { self.load_cb(ev, resourceNum); });
node.addEventListener("error", function(ev) { self.load_cb(ev, resourceNum); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment