When my page loads I execute JS to determine whether certain text fits inside its parent div. If it doesn't then stuff needs to be done.
The text uses a custom font, which is either loaded via @font-face or Google font, depending on the font.
The problem is that the JS sometimes runs before the font has been applied, leading to a wrong result since the fonts don't have exactly the same size/width.
EDIT, in response to comments:
I have the CSS in the header and the JS at the end of the document. I have now put all my code inside:
$(document).ready ( function(){...})
and the issue is still there.
When I have caching off then it measures the wrong height. When caching is on then it gets the right height, presumably because of the time to apply the font.
window.onloadfunction. That should delay it until everything is loaded.document.readyruns when the DOM is loaded, but doesn't wait for asynchronous elements to be loaded.