最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ResizeObserver one vs multiple performance - Stack Overflow

programmeradmin1浏览0评论

The ResizeObserver has an observe() method and an unobserve() method. This seems to encourage having one ResizeObserver instance and observing and unobserving different elements as needed with logic in the callback to handle each entity. Is there any performance implications of doing this vs instantiating multiple ResizeObservers for observing different elements or groups of elements?

The ResizeObserver has an observe() method and an unobserve() method. This seems to encourage having one ResizeObserver instance and observing and unobserving different elements as needed with logic in the callback to handle each entity. Is there any performance implications of doing this vs instantiating multiple ResizeObservers for observing different elements or groups of elements?

Share Improve this question asked Jul 25, 2018 at 23:18 Wilhelmina LohanWilhelmina Lohan 3,0433 gold badges32 silver badges65 bronze badges 2
  • the unobserve method isn't encouraging reuse of a resize observer. It's a neccesity to allow proper garbage collection of listeners and elements – bryan60 Commented Jul 25, 2018 at 23:43
  • Like the MutationObserver, disconnect() can be used for garbage collection. – Wilhelmina Lohan Commented Jul 26, 2018 at 14:55
Add a ment  | 

1 Answer 1

Reset to default 11

Looks like reusing (one) the ResizeObserver is preferred and more preformant:

https://github./WICG/ResizeObserver/issues/59#issuement-408098151 https://groups.google./a/chromium/forum/#!msg/blink-dev/z6ienONUb5A/F5-VcUZtBAAJ

发布评论

评论列表(0)

  1. 暂无评论