Bundling workers


I am developing a cesium wrapper bundle for my client, and I use webpack for this.
Official cesium doc said that Workers directory should be copied to the dist target directory while building (with CopywebpackPlugin); but is it possible to put all the needed workers files inside the final bundle ? (instead of having it in a separate directory)

Thank you,

Those are required to be separate files because they are web workers that run in separate threads, and JavaScript requires these to be separate files.

For example, decoding models compressed with Draco will load the Draco decoder as web worker so it doesn’t freeze up the main application. But if you have no models using Draco encoding, then those files will not be loaded by your CesiumJS app. That way you can have a smaller bundle size that the user downloads by only requesting the functionality needed.

Thank U for answering Omar.
But how do I know which workers are used by my app ? or every files inside Workers dir should be present ?

Yes - the app won’t actually download all the worker files, unless they are used. So hosting extra files on your server won’t impact load time for your users.

1 Like