OiO.lk Blog javascript Reducing blocking time of GTag script
javascript

Reducing blocking time of GTag script


If you can recognise this:

<script src="https://www.googletagmanager.com/gtag/js?id=G-TOKENIDHERE"></script>

It is a heavy file for the first second and so it matters.
What I did:

  1. List item
  2. Used Async/Defer (but it still blocks)
  3. Loaded it in worker process via PartyTown, (see this stack answer)and the script loads, but cannot call "collect" calls, so no analytics. Google can detect the tag though.
  4. Copied the script contents from the url "googletagmanager.com/gtag/js?id=G-TOKENID" directly unto my page and that removed the blockage time. Although I am not sure this is okay.. There is nothing on the internet that mentions doing or not doing this.

The webpage is fully static and very less content, therefore getting blocked from rendering fast due to a third party analytics like this is undesired.



You need to sign in to view this answers

Exit mobile version