One intersectionObserver to observe many elements or one intersectionObserver per element

蓝咒 提交于 2021-01-21 04:25:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!