问题
We have a few CustomElements in our page and some of them have an IntersectionObserver relative to the viewport observing them. That number might be increasing as the designer seems to like intersection animations.
Will that lead to performance issues? Is it better to have one IntersectionObserver that observes all elements or many IntersectionObservers that only observe one element?
回答1:
As already stated, there are a lot of factors to consider!
I made the below library specifically for a media heavy site. A normal user session might setup and teardown > 1000 observers.
Since everything happens off the main thread it is hard to observer memory usage as show here. However, metrics showed us one IntersectionObserver for all the elements gave users an overall improvement. This package should be relatively easy to use!
https://github.com/snewcomer/intersection-observer-admin
来源:https://stackoverflow.com/questions/55867849/one-intersectionobserver-to-observe-many-elements-or-one-intersectionobserver-pe