Live data from Hacker News

When to use web workers

dassur.ma

21–30 of 110 posts

Re: When to use web workers

#21

Earlier quoted context omitted.

Static _is_ better for a good bunch of performance metrics. But what about interactive content like https://proxx.app ? The article is mostly aimed at use-cases where some sort of logic in JavaScript is required.

Yes @dassurma. But web workers are not everything. Your own blog post does not score 100 : https://developers.google.com/speed/pagespeed/insights/?url=... And those issues are not necessarily addressed with web workers. Good basic static design matters too.

I never claimed that Web Workers are the silver bullet that will absolve us from all our problems. On the contrary, I don’t think such a silver bullet will ever exist.

I am saying that we should be using web workers to keep the main thread free. That is completely orthogonal to good static design, proper bundling, right caching headers, code splitting, asset hashing etc etc.

Re: When to use web workers

#22

If there was a vdom library that moved the diffing part to a web worker, would you have used it? or is it still costly to do any diffing at all?

It's still costly, but at least it'd not be blocking the main thread. I'd definitely give it a try!

Did you ever consider using svelte? Or was it not around when you developed this site?

Re: When to use web workers

#23

Earlier quoted context omitted.

It's still costly, but at least it'd not be blocking the main thread. I'd definitely give it a try!

Did you ever consider using svelte? Or was it not around when you developed this site?

I have played with Svelte, not used it for any project yet.

When you say, “this site”, do you mean my blog? Because that one’s fully static using 11ty.

Re: When to use web workers

#25

Earlier quoted context omitted.

Did you ever consider using svelte? Or was it not around when you developed this site?

I have played with Svelte, not used it for any project yet. When you say, “this site”, do you mean my blog? Because that one’s fully static using 11ty.

Sorry I meant proxx.app

Re: When to use web workers

#26

Earlier quoted context omitted.

I have played with Svelte, not used it for any project yet. When you say, “this site”, do you mean my blog? Because that one’s fully static using 11ty.

Sorry I meant proxx.app

Ah, no Svelte was around, but we were on a pretty tight deadline and had a good amount of experience with Preact in the team. We didn’t feel comfortable increasing the risk by using an unknown framework.

Re: When to use web workers

#27
My experience with Web Workers was terrible. It's not because of the Web Workers itself but there is no proper standard way to use modules inside of the worker.

Because it requires a separated .js file to instantiate, bundlers like webpack tend to introduce weird and non-standard way to work with [1].

It is usually fine when you use it your own project since you are going to stick with a bundler you choose anyway, but the worst things happens when you try to publish a JS library that uses a web worker internally. You cannot just publish the source because bundlers won't recognize require() and imports syntax in the web worker source code out of the box.

There is a ES standard:

  new Worker("worker.js", { type: "module" }); 
but no browsers implementations yet and some people aren't happy with this because it is not async [2].

[1]: https://github.com/webpack-contrib/worker-loader/blob/master...

[2]: https://bugs.chromium.org/p/chromium/issues/detail?id=680046

Re: When to use web workers

#28

Has anyone used web workers at the edge ... like with cloudflare workers?

Despite the similar naming, "Web Workers" is a specific browser API that has nothing to do with "the edge" or any server-side thing.

Point is well taken. I have not tried cloudflare workers yet. It seemed like at least the architecture was the same. But I guess you would not have access to the full browser API. It seems like you can still play around with request / response side of things though.

Re: When to use web workers

#30

Earlier quoted context omitted.

Yes @dassurma. But web workers are not everything. Your own blog post does not score 100 : https://developers.google.com/speed/pagespeed/insights/?url=... And those issues are not necessarily addressed with web workers. Good basic static design matters too.

I never claimed that Web Workers are the silver bullet that will absolve us from all our problems. On the contrary, I don’t think such a silver bullet will ever exist. I am saying that we should be using web workers to keep the main thread free. That is completely orthogonal to good static design, proper bundling, right caching headers, code splitting, asset hashing etc etc.

I agree with you on keeping the main thread free. What are your thoughts on WASM via workers?
Post reply on HN