Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to suspend reflow during heavy DOM manipulations?

I need to do heavy DOM manipulations on the whole document of webpages in an Add-On I write. I would like to minimize the reflows so only one reflow happens for all my manipulations. Removing the body element, doing the manipulations and then inserting it again is not an option because this reevaluates all <script> elements. Currently I set visibility of the body to 'none' before the manipulations and restore the value of display after. I'm not sure if this is teh best way to deal with this, though.

Is there a better way? Of course it could be Firefox specific code. After all it's a Firefox Add-On.

like image 711
panzi Avatar asked Nov 15 '22 09:11

panzi


1 Answers

Gecko is actually pretty good at suppressing unnecessary modifications on its own (i.e., you may well be better off not messing with it), except when, in between the many modifications you're making, you're also requesting information that requires layout to be up-to-date (such as element positions or sizes, getComputedStyle, etc.)

like image 113
David Baron Avatar answered Jan 02 '23 13:01

David Baron