6

I'd like to know if there's a reliable way on modern web browsers to detect document reflows and/or repaints, or if there's any pressing interest for such a thing that might put it in a W3 spec.

I would also like to know how it can be accomplished at all using vendor-specific tricks (e.g. Mozilla apparently has a MozAfterRepaint event,) if it's not possible in a standard or cross-browser way.

Thanks.

Gui Prá
  • 5,559
  • 4
  • 34
  • 59
  • 1
    There is no real reason to capture that event, as it is unpredictable since frame rates vary. Use `requestAnimationFrame` to get closer to the redraw cycle. – Populus Apr 15 '14 at 18:15
  • possible dupe of http://stackoverflow.com/questions/7006152/how-do-we-investigate-how-many-times-a-browser-is-doing-reflows – Patrick Apr 15 '14 at 18:49

1 Answers1

0

You can't measure accurately but you can predict by looking through any javascript which is a getter or setter/changer of styling, animating, adding/removing classes on elements. This can be done by using javascript to ajax all the javascript on the page to get the javascript strings, and then use regular expressions to detect where they are. Create an object of all the method names you find that do this.

If you want to capture it in realtime, you could use a combination of the above, and currying all the methods on the page to call your own mediator to marry it up with your object reference above.

Steve Tomlin
  • 3,391
  • 3
  • 31
  • 63
  • 1
    Static code analysis to detect repaints and/or reflows? Who would go that far? Besides, that would only yield code points that might cause repaints and/or reflows, but you'd still have to somehow predict when such code points are reached. In other words, you'd have to modify the code to add event triggers. And besides still, JavaScript isn't the only thing that can cause repaints / reflows. Sorry, but this is an insane proposition. – Gui Prá May 03 '15 at 22:05
  • 1
    I would go that far because I believe in better debugging and better performance and freedom from bad frameworks. Once you know what causes reflows then thats the work done. Javascript can detect the css on the page - computed aswell. You have complete access to the Dom. It is possible but I didn't say it was going to be easy. it depends on the experience of the developer. – Steve Tomlin May 05 '15 at 05:42