MoOx/pjax

A question about executeScripts

stevenjoezhang opened this issue · 0 comments

pjax/index.js

Lines 208 to 213 in c26c223

// execute scripts when DOM have been completely updated
this.options.selectors.forEach(function(selector) {
forEachEls(document.querySelectorAll(selector), function(el) {
executeScripts(el);
});
});

forEachEls(el.querySelectorAll("script"), function(script) {
if (!script.type || script.type.toLowerCase() === "text/javascript") {
if (script.parentNode) {
script.parentNode.removeChild(script);
}
evalScript(script);
}
});

After script.parentNode.removeChild(script); is executed, script.parentNode will be null

var parent =
el.parentNode || document.querySelector("head") || document.documentElement;

This means that the return value of the short-circuit evaluation here is document.querySelector("head")

In other words, all the scripts that are refreshed by pjax will be placed in the <head>. Is this expected behavior?