Update #2:
I managed to limit the number of re-paints by using the Chrome Timeline tool (thank you @iambriansreed for the suggestion). This limitation seemed to solve the problem (will add answer below), or at least make it so infrequent that it's no longer an issue.
However, it still does a "Layout" render whenever I modify the innerHTML of an element (which is a lot with the plugin I am writing). I tried making it position: fixed
while I am modifying it (since that won't affect anything else in the layout except for itself), but it doesn't seem to make any difference.
Update #1:
It is not the .onload
function in particular that is causing this... it also happens on document.ready
. I think this is what is happening:
- document.ready fires
- for loop
- alert out the width (correct)
- window.onload fires
- for loop
- alert out the width (sometimes correct, other times 0)
- "cut up divs"
- repaint
Does anyone have any idea on how to detect when a repaint is happening so that I don't query it at that moment? (P.S. why does IE not "pause" while it paints?!)
On $(document).ready(...)
I run through a for loop twice and alert out the body's width ($('body').width();
) each time through. I get a value I would expect (ex. 1092).
On $(window).on('load', ...)
I run through another for loop twice, also alerting out the body's width each time through. I get 0 the first time through (and the page looks completely blank behind the alert), and then a value I would expect the second time through (ex. 1092).
This is an issue I am not able to replicate in a stripped-down example, nor any other browser (Chrome, Safari, Firefox, IE9, IE10).
Does anyone have any ideas, or other things that I could test for?
I am using $(window).on('load', ...)
to cut up some divs based on their width, which is based on their font size, which is based on a webfont (which isn't necessarily loaded by the time $(document).ready(...)
fires).