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

javascript - Minimise "Forced reflow" - Stack Overflow

programmeradmin2浏览0评论

TD;DR

I spend some time tracking the performance of our app, which implements highcharts. I figured out, that some function like getBBox() do trigger "Forced reflow" quite often.

If you look at this list What forces layout / reflow, the things that trigger a reflow is very long.

My Question:

Are there alternative for at least some of the listed properties (espacially offsetWidth/offsetHeight), that do NOT trigger a reflow?

TD;DR

I spend some time tracking the performance of our app, which implements highcharts. I figured out, that some function like getBBox() do trigger "Forced reflow" quite often.

If you look at this list What forces layout / reflow, the things that trigger a reflow is very long.

My Question:

Are there alternative for at least some of the listed properties (espacially offsetWidth/offsetHeight), that do NOT trigger a reflow?

Share Improve this question asked Oct 24, 2017 at 8:38 scipperscipper 3,1633 gold badges26 silver badges43 bronze badges 3
  • 1 In most scenarios, if you want a better performance on manipulating DOM elements, you should separate it into a new layer and use only the hardware accelerated transformations which do not trigger any reflow of the entire page. – Derek 朕會功夫 Commented Oct 24, 2017 at 8:41
  • @Derek朕會功夫 Very nice article. I tried to move one expensive element to a new layer, and it does reduce the reflow occurrences. The impact was not that massive, but it's a start. Thanks! – scipper Commented Oct 24, 2017 at 10:54
  • You can switch to canvas charts. – woxxom Commented Oct 24, 2017 at 16:48
Add a ment  | 

1 Answer 1

Reset to default 7

Are you familiar with docs like Avoid forced synchronous layouts? The main idea is to do all of your read operations before your write operations that change the layout of an element. As long as you follow that principle it's less important what properties you use. Although of course it's always a good idea to use properties that do as little work as possible.

.High-Performance Animations is a good resource on what properties are efficient though. This relates to the layers approach that Derek mentioned.

发布评论

评论列表(0)

  1. 暂无评论