- Don't call getComputedStyle as much as possible.
- Don't call it in a loop (multiple force render.)
- If you have to have do it.
a. do it at the debounce & after request animation frame. (Thus blink is already eval most of the data that you ask for.)
b. stamp the class that you are looking for rather than ask the style to get for it.
...Returned values are sometimes deliberately inaccurate. To avoid the “CSS History Leak” security issue, browsers may lie about the computed styles for a visited link, returning values as if the user never visited the linked URL...
Tthe
getComputedStyle()
ends up forcing a layout redraw / reflow, see:In testing this really seems to happen on calls to
getPropertyValue()
as seen here:Consider the strategy from the referenced issues:
Not to mention, according to the specs (https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle) the values may be intentially incorrect.