electerious / ackee-tracker

Transfer data to Ackee.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The script causes visible layout issues when loading

makew0rld opened this issue · comments

The Firefox console notifies me that:

Layout was forced before the page was fully loaded. If stylesheets are not yet loaded this may cause a flash of unstyled content.

It also says that the problem is at 1:15966, aka the 15,966th character in the script.

It is correct, as I was able to see repainting occur, where the style loaded once incorrectly, and then was corrected. This doesn't happen when I remove the script, but occurs no matter where I place it, at the bottom, at the top, without async, with defer, etc.

You can take a closer look at the source, but I'm not aware of something that could trigger a layout change. It doesn't occur on my sites.

Let me know if you find out more.

My site is https://www.makeworld.gq/ or here on Github. When I remove the script their are no more loading issues. Can you confirm this with my site?

It's caused by a function called isScrollable. This function isn't part of Ackee.

Thanks so much for looking at it. Where is that function in my website?

Because I don't see how isScrollable could come up anywhere.

commented

You can "prettify" sources, so you can actually see normal code:

image

clicking that, we can now see that this is actually ackee, because of this line:

browserWidth:
            document.documentElement.clientWidth || window.outerWidth,

Asking the browser for clientWidth forces the browser to evaluate the DOM, even if it wasn't ready to do that yet, hence the "Layout was forced before the page was fully loaded" error.

@Pomax Aha! Thanks for figuring this out. @electerious Can you update the script to not require this? Seems like you can just use window.outerWidth maybe?

Good to know. We can switch to window.outerWidth and window.outerHeight as we're talking from the browser width/height anyway. document.documentElement.clientWidth is the width of the website area (without the browser toolbar, sidebar and other panels).

PR welcome!

I've adjusted the script. The issue will be fixed in the next release of ackee-tracker.