performancepagespeedpagespeed-insightswebpagetest

What are impacts of firing scripts only after user action?


I'm currently on loading time optimization of a site. On my research of sites using the same consent solution, I found a site, which loads most scripts, including GTM/GA, only after any user action. The site has surely great loading times under 2 seconds.

Most scripts means - usual scripts, which cause TBT (tracking, without above-the-fold coverage).

As for now, I see only one negative impact: GA can't count bounce rates.

Do you see any further negative impacts of loading scripts after user action?


Solution

  • When done well, this can get scripts that aren’t needed for page load out of the critical path and let the browser concentrate on what is important for page load.

    However there are a number of downsides.

    When done badly, with a broad “don’t load any scripts” hammer, then scripts that ARE needed for page load don't run. Carousels don’t load, or other important content. The page looks broken until the user moves the mouse. So it’s important to allow scripts needed for load to execute early. And to test this (on a variety of screen sizes) rather than assume you can delay everything without ill consequences.

    Also if the script is only loaded and executed on interaction, and it takes a while to load and execute, then it can also lead to poor performance. It’s not unusual to see hamburger menus being really slow to respond to the first click, but then after it’s fast. Which is a classic sign of this pattern

    Finally, as you point out, analytics and the like can be delayed.

    I can’t help but think that’s sometimes delaying of scripts is done to trick tools like Lighthouse and make a page look faster (“Install this plugin and get 100 Performance score!” [even though the page is broken]) without enough thought as to whether it’s actually making the page better.