Lazy-Loading / Delay X Number of JavaScript

TL Version; DR

Pretty simple question, what is the best way to lazily load or delay low-priority JavaScript? Given that it can be anything: from Google Analytics, Optimization, Testing and Targeting to custom code. All downloaded using Adobe DTM.

Longer version

We analyzed our traffic and found that slow loading times caused less sales, and not surprisingly. Unfortunately, much of JavaScript is inflated by a separate department, and it only gets worse with load times in excess of 10 seconds .

The evil side of me wants to host the page load and setTimeout event on an Adobe DTM script to delay code until much later. But this will have a side effect of page load events in vendor code that is not executed properly.

The best solution I have today is to add a page load event to the page to load Adobe DTM by adding an element <script>to the tag <body>. Essentially, we need the application code to download first, and the marketing code should load in the background without affecting the website.

Can anyone suggest a better solution?

+4
source share

Source: https://habr.com/ru/post/1651984/


All Articles