-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Feat: Run angular in web worker mode #2305
Comments
Currently also looking for a good way to accomplish it. Any1 got a workaround for now? |
No support at the moment, but we are looking at it. |
Any news here? |
I'm also curious if there have been any updates to this. |
Also looking for this. |
... need this feature!!! |
For those who can't wait, I've found a good post on stackoverflow. I've heard of Angular running in a webworker in the early days of angular. Now I'm just wondering whether I'm gonna wait for built in solution with the cli or |
The stackoverflow approach seems reasonable. Would a PR with this be welcome here? |
Gotta try to find out @bmayen ! Seriously I think that yes it'd be welcome and even tho it might not be perfect the first time after few iterations it might go to master ... 😃 Don't forget to reference this issue if you try something so we can follow what's going on 👍 ! |
@maxime1992 Thanks for posting that, I'm not sure why workers (--mobile) were cut from angular-cli. |
This is something that we've been exploring. There's currently limited experimental support that you can try by doing:
Now /cc @alxhub |
@filipesilva, your comment refers to a service worker, but the issue pertains to web workers. Typo or am I missing something here? |
@filipesilva dude there is fundamental difference between webworker and serviceworker. |
Sorry guys, this was a major durf on my part. Completely misread the issue. |
Service workers would still be nice to have. They don't yet have full modern browser support though, so not as urgent IMO. Web workers on the other hand... :) |
@bmayen Service workers are available, very nice tutorial here: https://docs.google.com/document/d/19S5ozevWighny788nI99worpcIMDnwWVmaJDGf_RoDY/edit# |
@mwent-cray, this document is all about Service Workers, not Web Workers. They are different things with different objectives. |
The tutorial posted by Enrique here:https://medium.com/@enriqueoriol/angular-with-web-workers-step-by-step-dc11d5872135 using the ng eject approach works for a basic app, I tried to get it to work on my Angular 4 application but I had to get Has anyone had any luck getting webworkers with ng eject working ? |
Unfortunately not, but haven't done too much additional research into it. Our webworker apps simply do not use Angular CLI now :( Not that we wouldn't love to migrate them over though! @filipesilva, is there any chance of bumping this priority up from "nice to have"? I'd argue that it's higher than that because it's major Angular functionality which isn't supported. |
Bump. |
Could that be helpful to a smooth integration with the CLI? |
No news about this??? 😴😴😴😴 |
Having the choice to do it would be really nice |
@maxime1992 there's ongoing work to add that plugin in #12575. |
One of the problems is when you load modules and material2 animations get stuck. |
Material2 works with DOM manipulation, so it won't run in a web worker. |
Yes, but maybe the loading of the modules could be done in a web worker. |
Any news on that? people are existed with that feature. |
with the Are there any updates/workarounds and how to do this considering that ejecting is not possible anymore? this was one of the most exciting features about angular that was show cased in ng-conf when angular2 was first released. |
@khaledosman I've been trying to implement this for a little while. I got some results but it's still a work in progress. Here is what I've been doing so far:
src/main.ts
src/app/app.module.ts
angular.json
webpack.client.config.js
src/workerLoader.ts
Running If I remove the If anybody here figures something out, let me know. I'll keep digging. |
Hey guys! I got this to work with Angular7! Here is copy of my StackOverflow answer: Good news guys, I got this to work with Angular 7! 🎉🎉🎉 Requirement: Step 1: Edit your angular.json file the following way:
You are only editing the Step 2: Create
Step 3: Edit you AppModule:
Step 4: Edit you main.ts file.
Step 5: It will compile just fine, but you may have a runtime issue due to DOM manipulation in your app. At this point you just have to remove any DOM manipulation and replace it by something else. I'm still working at figuring this part out and will edit my answer later to give direction about this issue. If you're not doing savage DOM manipulation, then you're good to go with a free main-thread and auditing your app using lighthouse should not show |
@glemiere it gives me webworker.bundle.js not found |
@glemiere good work. Is angular official support for this ever gonna be a thing ? |
|
Indeed @bmayen it's not officially deprecated in v8 angular/angular@361f181 That is a huge disappointment. We were all very excited about this. I will be digging into making a library to make this behavior possible and developer friendly, any help is welcome. Thanks everybody for the hard work💪 |
Running Angular itself in a Web Worker (via |
I came across web workers recently and early thoughts went into the direction of
I just flipped the idea the other way around:
You would end up with a style of code like this: // All worker-compatible code goes to @my/worker
import { WorkerFacade, workerCompatibleCode } from '@my/worker';
// WorkerFacade would implement the "if no worker" fallback and messaging from UI to worker
const myWorker: WorkerFacade = /* ... */
const runnableInWorker = myWorker
// You would need to map messages to function calls in the worker (not shown here)
.postToWorker({ run: 'workerCompatibleCode', data: { foo: 'bar' } })
// workerCompatibleCode() would be run in the UI were web worker isn't available
.orElse(() => workerCompatibleCode());
runnableInWorker.subscribe(result=> {
console.log("result was returned either from a web worker or from UI process");
}); |
Running Angular inside a web worker has been deprecated for a while now, as it just isn't typically beneficial for performance: https://angular.io/guide/deprecations#webworker-apps. As a result, the CLI doesn't support this use case anymore. Applications can still add web workers to run their own CPU-intensive tasks, just not running Angular itself. See https://angular.io/guide/web-worker for more on that. |
I'd really like to use angular's dependency injection system in my web workers. I have a bunch of heavily modularized Angular services that rely heavily on the Angular DI system. I'd like to use some of those services in a web worker (even if it meant instantiating a secondary service tree that lived on the web worker side.) Does anyone have any suggestions on how to replicate that kind of approach in a web worker? Ideally reusing the actual service code, if possible? |
@pshields I assume using Angular DI system directly into a webworker would be hard but I remember that Minko extracted the DI part into a separate project which is browser agnostic (can work on Node) 🎉 https://github.com/mgechev/injection-js Maybe this will help you |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
In current setup there is no possibility to bootstrap angular in web worker mode.
Please add this killer functionality.
The text was updated successfully, but these errors were encountered: