On a client's site I have an element, which produces CLS, content layout shift
. This element is not critical for the site's functioning.
According to Nic Jansma, CLS measuring ends up with onLoad
event.
My idea is to remove this element from the source code and load it after onLoad
event with Google Tag Manager. Sadly I can't go the usual way, because of the issue nr. 3, according to Simo Ahava's classification.
<script>
var d1 = document.getElementById('article');
d1.insertAdjacentHTML('afterend', '<div id="quicknavi-button-container">Content</div>');
</script>
What should I adjust on my javascript? It fires an error I can't interpret:
Cannot read properties of null (reading 'insertAdjacentHTML')
` tag, because it can't find element with id="article" that is probably no rendered yet. This have nothing to do with CLS and Google Tag mangager.
– jcubic Nov 28 '21 at 14:31