Open carcinocron opened 7 years ago
Interesting Question. I think the right layer to solve this would not be Vue's DOM updates, but the data updates.
If we somehow halt the DOM updates, it will be very complicated to somehow cache them and do them all as soon as the tab is active again.
I expect my average user to be slammed with DOM updates from websockets.
I assume what is really happening is the user being slammed with data updates from the websocket, and then DOM updates happen due to Reactivity recognizing those updates, right?
So this could be solvable quite easily if you use vuex. We could overload the store's commit
method to cache all incoming calls when the tab is in the background, and only apply them when the tab is visible again.
Made a quick PoC: https://jsfiddle.net/Linusborg/swaeed82/
We could possibly extend this with a blacklist or whitelist for certain mutations to keep other functionalities working.
I've done this for my own project. If I find time, I'll upload it as an npm package this weekend, or next week.
It's not that hard, by the way... Caching, re-activating the updates, etc... I did it.
My primary goal: save battery life and increase performance for users running Chrome and/or Firefox (or any browser that supports the appropriate APIs).
Recent discussion titled: "Chrome will aggressively throttle background tabs"
https://news.ycombinator.com/item?id=13471543
What does Vue.js do when the tab is in the background (user is looking at another tab, might return in future). Chrome will throttle tabs that don't have active websockets/audio. I do have an active websockets on my application and I expect my average user to be slammed with DOM updates from websockets.