Skip soft reload if not needed.
This commit is contained in:
parent
93bca61c92
commit
1d583e17f4
|
@ -19,6 +19,7 @@
|
||||||
// Mozilla has already parsed the <head> element, we must take extra steps...
|
// Mozilla has already parsed the <head> element, we must take extra steps...
|
||||||
|
|
||||||
let softReloading = true;
|
let softReloading = true;
|
||||||
|
let suppressedScripts = 0;
|
||||||
debug("Early parsing: preemptively suppressing events and script execution.");
|
debug("Early parsing: preemptively suppressing events and script execution.");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -57,7 +58,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
let {readyState} = document;
|
let {readyState} = document;
|
||||||
debug("Readystate: %s, canScript: ", readyState, ns.canScript);
|
debug("Readystate: %s, %suppressedScripts %s, canScript = %s", readyState, suppressedScripts, ns.canScript);
|
||||||
if (!ns.canScript) {
|
if (!ns.canScript) {
|
||||||
for (let node of document.querySelectorAll("*")) {
|
for (let node of document.querySelectorAll("*")) {
|
||||||
let evAttrs = [...node.attributes].filter(a => a.name.toLowerCase().startsWith("on"));
|
let evAttrs = [...node.attributes].filter(a => a.name.toLowerCase().startsWith("on"));
|
||||||
|
@ -71,6 +72,13 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (suppressedScripts === 0 && readyState === "loading") {
|
||||||
|
// we don't care reloading, if no script has been suppressed
|
||||||
|
// and no readyState change has been fired yet
|
||||||
|
softReloading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let softReload = ev => {
|
let softReload = ev => {
|
||||||
let html = document.documentElement.outerHTML;
|
let html = document.documentElement.outerHTML;
|
||||||
try {
|
try {
|
||||||
|
@ -143,7 +151,8 @@
|
||||||
debug(e.type, e.target, softReloading); // DEV_ONLY
|
debug(e.type, e.target, softReloading); // DEV_ONLY
|
||||||
if (softReloading) {
|
if (softReloading) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
debug("Blocked early script", e.target);
|
++suppressedScripts;
|
||||||
|
debug(`Suppressed early script #${suppressedScripts}`, e.target);
|
||||||
} else {
|
} else {
|
||||||
removeEventListener(e.type, scriptSuppressor);
|
removeEventListener(e.type, scriptSuppressor);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue