Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web workers support #1334

Open
MurhafSousli opened this issue Jul 6, 2019 · 5 comments
Open

Web workers support #1334

MurhafSousli opened this issue Jul 6, 2019 · 5 comments

Comments

@MurhafSousli
Copy link

MurhafSousli commented Jul 6, 2019

Type of Issue

[ ] Bug Report
[X] Feature Request

Description

I need to use web worker for image processing library, and I am wondering if it is possible to generate a web worker inside the library and make it work out of the box for consumers?

Currently, my workaround is to add an inline script as a blob url and create a worker with it.

However the downside of this workaround is that you won't be able to use {type: 'module}. and it is not possible to use 3rd party libraries such as rxjs.

A feature: please describe your use case and motivation

It would be very useful if we can generate web workers and integrate them in the library without
requiring users to manually configure them.

Expected Behaviour

A feature: do you have a first draft or an idea how to implement?

Not sure if it is possible.

@dherges
Copy link
Contributor

dherges commented Jul 6, 2019

Don't think its possible. new Worker() requires a URL and that can only be done by the app.

@alan-agius4
Copy link
Member

alan-agius4 commented Jul 6, 2019

Running code in web workers should be handled at an application level.

iMHO, a library should offer a set of features and than its up to the consumer if these features should be run in a web worker or the not.

@Betalos
Copy link

Betalos commented Jul 9, 2019

@alan-agius4, if I am creating a libray with a service that is doing an intensive work. the issue here is that I won't be able to pack it cuz the worker specification worker must be seperate file.
So how would I be able to acheve this ???

@alan-agius4
Copy link
Member

Some things to consider when using web-workers in a library.

  1. The library will need to provide an alternative for browsers which don't support web workers or require SSR.

  2. Libraries will need to include any polyfills needed for the web worker code to run in older browsers this is because web workers run in a contained they don't share any of the bundles of your application. More info here: [differential loading + web workers] es5 worker doesn't load polyfills angular/angular-cli#15033 (comment)

From an ng-packagr perspective it is currently not possible to include web-workers, the main reason is that web workers need a separate compilation from the library itself which is currently not possible.

@Betalos
Copy link

Betalos commented Jul 15, 2019

@alan-agius4 well now as work around, I wraped the worker code as string and then exported it as an objectUrl with javascript as mime. we can think to laverage webpack's worker-loader for the worker bundling.
PS: using only a javascript based file bundled with the library some time angular optimizer can miss the file up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants