'Single Page Application - GTM script add duplicate script blocks for every page visit
Our website primarily has a Single Page Application (SPA) behaviour. We use Google Tag Manager to deploy all our tags and makes use of the History API in some cases to detect a scenario such as an URL change etc.
Recently, we noticed that as a user navigates through pages the following happens:
Example with Google Ads Double Click script:
User lands on Page A - GTM dynamically load the Double Click script (expected behaviour).
User clicks on a tile and goes to Page B - GTM dynamically loads Double Click script. However, the previous Double Click script (from Page A) is also still there.
User goes to Page C - GTM dynamically loads Double Click script. However, the previous Double Click scripts (from Page A and B) are also still there.
As a result, the webpage size grows due to multiple scripts and we are experiencing a big memory leak, the more time the user spends on our website.
This happens with all scripts that are supposed to fire on a particular page.
How can we avoid this memory leak from happening? Greatly appreciate all the support anyone can provide.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
