<story><title>When to use web workers</title><url>https://dassur.ma/things/when-workers/</url></story><parent_chain></parent_chain><comment><author>jwr</author><text>I have a large ClojureScript app (&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;partsbox.io&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;partsbox.io&amp;#x2F;&lt;/a&gt;) and I really, really wanted to use WebWorkers. I wanted to run larger tasks like indexing for search, or pricing calculations in WebWorkers.&lt;p&gt;But it seems to me that Webworkers were designed with an extremely narrow use case in mind. The restrictions placed on them make them essentially useless for me. To do anything ever remotely useful, I would need to duplicate my entire database in web workers, and then communicate with them through a thin straw. Database updates would need to be performed both in the main app database and in web worker threads.&lt;p&gt;The way they are restricted, I just can&amp;#x27;t figure out how to make any meaningful use of them.</text></comment>
<story><title>When to use web workers</title><url>https://dassur.ma/things/when-workers/</url></story><parent_chain></parent_chain><comment><author>kbumsik</author><text>My experience with Web Workers was terrible. It&amp;#x27;s not because of the Web Workers itself but there is no proper standard way to use modules inside of the worker.&lt;p&gt;Because it requires a separated .js file to instantiate, bundlers like webpack tend to introduce weird and non-standard way to work with [1].&lt;p&gt;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&amp;#x27;t recognize require() and imports syntax in the web worker source code out of the box.&lt;p&gt;There is a ES standard:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  new Worker(&amp;quot;worker.js&amp;quot;, { type: &amp;quot;module&amp;quot; }); 
&lt;/code&gt;&lt;/pre&gt;
but no browsers implementations yet and some people aren&amp;#x27;t happy with this because it is not async [2].&lt;p&gt;[1]: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;webpack-contrib&amp;#x2F;worker-loader&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;README.md#config&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;webpack-contrib&amp;#x2F;worker-loader&amp;#x2F;blob&amp;#x2F;master...&lt;/a&gt;&lt;p&gt;[2]: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;bugs.chromium.org&amp;#x2F;p&amp;#x2F;chromium&amp;#x2F;issues&amp;#x2F;detail?id=680046&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;bugs.chromium.org&amp;#x2F;p&amp;#x2F;chromium&amp;#x2F;issues&amp;#x2F;detail?id=680046&lt;/a&gt;</text></comment>