Why a reflow triggered by analytics.js:1520 [google-analytics]

Viewed 328
2 Answers

This document claims that a reflow is triggered for clientWidth and clientHeight even when they are being read (not just when set). However the author also points out that

Reflow only has a cost if the document has changed and invalidated the style or layout. Typically, this is because the DOM was changed [...]

which the analytics script does not do. So there seems to be a reflow, but I doubt that it come with a big performance penalty. In any case you will not get rid of this.

The article also links to a lot of other posts that discuss forced reflow issues.

Thanks for your answer. I believe this warning was accurate and need to be addressed as stated in https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing#avoid-forced-synchronous-layouts .

By following up the callstack I realized that one of our script was adding a class to the body after first rendering and this was apparently the cause of the reflow. I still do not really get why analytics is the script raising this warning in Performance tab, I guess it might watch body size change.

Best regards

Related