5 ms·
Run Third-Party Scripts from a Web Worker
- chrisweekly 4y agoPartytown seems like such a great idea; it's easy to imagine an alternate universe in which something just like it took off and today it'd be considered nuts not to use it.
- todd3834 4y agoVery cool! I wonder how they get around all of the “window” related APIs. I imagine you can pollyfill some of them but I would expect some random bugs here and there? I hope I’m wrong because this is otherwise great. This should also be something that providers of 3rd party scripts should take notice of when developing. Why not design to be in a web worker from the start if you can…
- kevincox 4y agoMy impression is that the "default" approach is not to pollyfill but proxy the calls to the main thread. They have a post about how they are (ab)using synchronous XMLHttpRequest calls to block the worker while proxying the request to the main process with postMessage https://dev.to/adamdbradley/how-partytown-s-sync-communication-works-4244 https://dev.to/adamdbradley/how-partytown-s-sync-communicati.... I suspect that you may want to pollyfill APIs for performance but I think for many use cases just that shim to the true API should work well enough.
- earthboundkid 4y agoIt’s a truly evil genius hack. XHR has a legacy synchronous API. So what they do is make a fake window object and any time something touches it, they do an async call out to the real window, but they make it look synchronous by doing the call via XHR to itself. Such a crazy hack!
- earthboundkid 4y agoI tried to use this in production, but it ended up breaking some random GTM tags our marketing firm added to the site, so I had to roll it back. God, I wish I could use it though. I hate the whole idea of GTM. It’s such a crap ecosystem. I’d love to just put it in a sandbox and tell it not to touch anything.
- toastal 4y agoThe funny part is that good browsers and smart users are already blocking all of those Google scripts. Then marketing departments end up designing the product around the dubious numbers from only the users that aren't wise enough to be blocking it leading the everyone the wrong direction.
- austinpena 4y agoNot my experience. 1. Serverside GTM and segment proxied through a first party domain get around ad blockers 2. Many traditional paid media sources like Facebook ads open in in-app-browsers that are unlikely to have ad blockers 3. Marketing and product analytics tend to be separate.
- todd3834 4y agoIt never occurred to me that the user installed content blockers don’t apply to in app browsers. Thank you for pointing this out.
- toastal 4y agoIt's the reason you should have host blocking on your device, but help a friend with hosts blocking on your network.
- fulafel 4y agoAd blockers also block by path, they do catch GTM.
- leerob 4y agoPartytown is very exciting. We've been working with the team at Builder to implement it inside the Next.js script component, using the `worker` strategy. `next/script` helps you optimize loading third-party scripts, so Partytown was a great fit. Folks at Builder are a pleasure to work with. https://nextjs.org/docs/basic-features/script#offloading-scripts-to-a-web-worker-experimental https://nextjs.org/docs/basic-features/script#offloading-scr...
- fulafel 4y agoSandboxing and monitoring/controlling API use of 3rd party scripts sounds really interesting. Are there any limitations of the webworker approach to this? Compared to eg using a js-in-js interpreter.
- jeroenhd 4y agoLooking at the example scripts this tool lists, I wonder if I should just add it to my adblock lists. Seems like an easy solution to block all manner of cyberstalking in a one go. Looks like a good solution to a very strange tool. If your web pages are bogged down by external scripts enough for this to matter, why not get rid of the bloat instead of letting it consume precious battery power in a secondary thread?
- no_time 4y ago>Below are just a few examples of third-party scripts that might be a good candidate to run from within a web worker. The goal is to continue validating commonly used services to ensure Partytown has the correct API, but Partytown itself does not hardcode to any specific services. Help us test and join the conversation in Partytown’s Discord! Google Tag Manager (GTM) Google Analytics (GA) Facebook Pixel Mixpanel Hubspot Segment Amplitude A great selection of scripts which I don't want to run under any circumstances.