These run after first interaction or the fallback timeout.
========================================================= */
function loadDelayedScripts() {
if (
delayedScriptsStarted
) {
return;
}
delayedScriptsStarted =
true;
document
.querySelectorAll(
'script[type="text/plain"]' +
'[data-rh-delay-src]'
)
.forEach(
function (placeholder) {
var src =
placeholder.getAttribute(
"data-rh-delay-src"
);
if (!src) {
return;
}
loadScript(
src,
{
id:
placeholder.getAttribute(
"data-rh-script-id"
) || undefined,
async:
placeholder.getAttribute(
"data-rh-async"
) !== "false",
defer:
placeholder.hasAttribute(
"data-rh-defer"
)
}
);
}
);
}
onFirstInteraction(
loadDelayedScripts
);
/* =========================================================
ROUTE / PAGE INITIALISATION
---------------------------------------------------------
One media pass:
- initial load
- browser page restore
- custom GHL route change
No permanent DOM MutationObserver is used because avoiding
a site-wide observer keeps overhead lower.
========================================================= */
function initialise() {
optimiseMedia(
document
);
}
ready(
initialise
);
window.addEventListener(
"pageshow",
initialise
);
document.addEventListener(
"rh:route-changed",
function () {
/*
* Give the router one frame to finish inserting
* the replacement page.
*/
window.requestAnimationFrame(
initialise
);
}
);
/* =========================================================
PUBLIC API
========================================================= */
window.RHPerf =
Object.freeze({
settings:
SETTINGS,
ready:
ready,
idle:
onIdle,
onFirstInteraction:
onFirstInteraction,
rafThrottle:
rafThrottle,
debounce:
debounce,
optimiseMedia:
optimiseMedia,
bindImageMap:
bindImageMap,
loadScript:
loadScript
});
})(
window,
document
);