BuilderIO / partytown

Relocate resource intensive third-party scripts off of the main thread and into a web worker. 🎉
https://partytown.builder.io
MIT License
12.97k stars 427 forks source link

[🐞] on simulated fast and slow 3G connections, the scripts fail to load as expected #481

Open John-Nik opened 11 months ago

John-Nik commented 11 months ago

Describe the bug

When testing to see how the website loads on slow and fast 3G connections, it fails to load the scripts as expected. Once the website loads with an unthrottled internet connection, the scripts load as expected

Reproduction

https://github.com/JohnN-Resonat/website/tree/main

Steps to reproduce

On DevTools, set the network speed to a slow or fast 3G connection

Browser Info

Chrome

Additional Information

No response

gioboa commented 11 months ago

Hi @JohnN-Resonat can you explain the problem again pls? I don't understand the issue

John-Nik commented 11 months ago

Hi @gioboa. The problem is appearing when I try to simulate a slow network through DevTools. When I simulate a slow 3G network, the PartyTown framework fails to work as expected, resulting in none of the instructed scripts to run.

From what I've noticed, the issue is that the "Partytown 🎉" web worker kills itself after some time of inactivity during the time period of the page's initial loading.

I am not aware what variable it's taking to make the judgement to kill itself (e.g. does it have a time awaiting for input, does it check all the site's requested assets are downloaded or something else).

One last thing to add. When the website finishes downloading all it's requested assets, IF we allow it to cache, then once we reload it, PartyTown Works as expected. If we disable caching, the problem persists.

Another unrelated issue I've encountered is that when the website is not viewed, and instead loading in the background, PartyTown stops working again.

I hope my explanation was clarifying enough

Edit: I forgot to mention that window.dispatchEvent(new CustomEvent('ptupdate')); doesn't fix the problem

gioboa commented 11 months ago

I see. Would you like to drop a PR for these issues?

John-Nik commented 11 months ago

I see. Would you like to drop a PR for these issues?

Because I am new to GitHub, I don't know how to drop a pull request. Could you provide some assistance?

gioboa commented 11 months ago

I see. Would you like to drop a PR for these issues?

Because I am new to GitHub, I don't know how to drop a pull request. Could you provide some assistance?

This guide is accurate 😉 pls have a look