You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm testing a little bit modified version of the JS:
/** * Change `delay` attributes back to `src` attributes. * * @return void */functionprint_delay_js(){
?><script>
var delayLoaded = false;
var autoLoadDuration = 5;
var eventList = ["keydown", "mousemove", "wheel", "touchmove", "touchstart", "touchend"];
var autoLoadTimeout = setTimeout(runScripts, autoLoadDuration * 1000);
eventList.forEach(function(event) {window.addEventListener(event,triggerScripts,{passive: true})});
function triggerScripts() {runScripts();clearTimeout(autoLoadTimeout);eventList.forEach(function(event){window.removeEventListener(event,triggerScripts,{passive: true});});}
function runScripts() {if(!delayLoaded){document.querySelectorAll("script[data-cookieconsent]").forEach(function(scriptTag){<?php// Create new script tag and replace "delay=" with "src=". ?>varnewNode=document.createElement('script'); newNode.setAttribute("data-cookieconsent", "ignore"); var newContent = scriptTag.textContent.replace("delay=", "src="); newNode.textContent = newContent; scriptTag.parentNode.replaceChild(newNode, scriptTag); }); document.querySelectorAll("script[delay]").forEach(function(scriptTag) { <?php // Replace "delay=" with "src=" attribute. ?> scriptTag.setAttribute("src", scriptTag.getAttribute("delay")); }); } delayLoaded = true; } </script> <?php}add_action( 'wp_head','print_delay_js');
Suggestion for new data attribute
In the above code I'm using document.querySelectorAll("script[data-cookieconsent]") to detect GTM code. It doesn't feel like bullet proof because we might not even have Cookiebot on the page.
We should have our own data attribute, for example data-meom-delay and hook into that:
There is interesting approach to delay 3. party JS.
I'm not suggesting to delay our JS by default but document how it can be done.
Change
src
attributes todelay
attributes.We already have filters for this:
Add custom JS
I'm testing a little bit modified version of the JS:
Suggestion for new data attribute
In the above code I'm using
document.querySelectorAll("script[data-cookieconsent]")
to detect GTM code. It doesn't feel like bullet proof because we might not even have Cookiebot on the page.We should have our own data attribute, for example
data-meom-delay
and hook into that:document.querySelectorAll("script[data-meom-delay]")
.The text was updated successfully, but these errors were encountered: