ndarville / goal-tracker

Track the goals, promises, and predictions of those we want to hold accountable. Inspired by <trudeaumetre.ca>
https://ndarville.github.io/goal-tracker/
6 stars 0 forks source link

Delay loading of fonts #3

Closed ndarville closed 8 years ago

ndarville commented 8 years ago

Might consider abandoning it altogether.

Right now, font loading takes up more than two thirds of the page size—(80%):

screen shot 2015-11-20 at 11 11 37

That’s ridiculous. Find a proper fallback for skeleton.css projects.

ndarville commented 8 years ago

Via http://keithclark.co.uk/articles/loading-css-without-blocking-render/.

ndarville commented 8 years ago

screen shot 2015-11-20 at 12 39 06

This thwarts the font blocking the remaining loading and rendering with a significant boost to DOMContentLoaded. Looks like it also shaved off 7 kB somehow.

ndarville commented 8 years ago

Shortcomings:

  • This method does not work in Android < 4.4 because the onload handler does not fire when content is available - I’m looking into a work around for this.
  • Some browsers appear to still block CSS render despite media=“none”. This means CSS loads as it usually would — I’m looking into this.

http://keithclark.co.uk/articles/loading-css-without-blocking-render/

Android < 4.4 is 36.3% of all Android devices cf. http://developer.android.com/about/dashboards/index.html.

Worst-case scenario, the website renders without downloading the font (a nifty way to enforce a performance gain).

ndarville commented 8 years ago

FOUT—when you throttle the connection to slow things down:

screen shot 2015-11-23 at 09 52 49

ndarville commented 8 years ago

It’s tempting to add the font-family CSS farther down the DOM, but the problem is that it creates a race condition—which is always going to lose due to the size of the fonts.

ndarville commented 8 years ago

On a 3G connection—current:

frame_0000 frame_0013 frame_0023 frame_0029 frame_0031 frame_0034


filmstrip 1

ndarville commented 8 years ago

On a 3G connection—current:

frame_0000 frame_0024 frame_0029 frame_0032 frame_0035


filmstrip 2

ndarville commented 8 years ago

Just the two:

filmstrip 1 filmstrip 2

ndarville commented 8 years ago

So that wasn’t an improvement—in fact, it was the opposite. Could be it’s a Chrome thing, and not Safari which I tested on?

ndarville commented 8 years ago

This article describes the delayed FOIT problem with delayed font loading.

ndarville commented 8 years ago
ndarville commented 8 years ago

From what I understand:

  1. Delay loading of font
    • DOM loads faster due to removal of blocking fonts
  2. FOIT occurs after DOM is finished loading, because the DOM is repainted with new font

At first we wondered if the blink was just an artifact of repainting/reflowing a moderately complex layout. But the characteristic hidden text alongside visible graphic elements sure looked like your run-of-the-mill FOIT, and sure enough, it was. In short, a FOIT happens when a browser attempts to style an HTML element with a font-family that is defined (via a @font-face declaration) but not yet loaded. Interestingly enough, in this case it appeared that although the CSS and its included fonts had indeed already been delivered over the network to the browser, the browser still seemed to hide the text while parsing the data URI string, which we know can take a little time, particularly on slower devices.

ndarville commented 8 years ago

Uhhh:

Before reverting:

filmstrip-2 waterfall php-3

No intermittent FOIT.

ndarville commented 8 years ago

After reverting:

filmstrip-3 waterfall php-4

ndarville commented 8 years ago

Renders 300ms faster—but the FOIT lasts 700ms. Let’s hope this tweak fixes it.

ndarville commented 8 years ago

After delaying re-painting using fontfaceobserver (based on this fontfaceobserver article).

ndarville commented 8 years ago

There’s a flash of FOUT now instead. Could create an option to allow people to choose which they prefer.

ndarville commented 8 years ago

After:

filmstrip-4 waterfall php-5

ndarville commented 8 years ago

Loads 100ms faster but has 500ms of FOIT. That shouldn’t be the case.

ndarville commented 8 years ago

Implemented checks for all three fonts.

ndarville commented 8 years ago

This fixes the FOIT; after implementing checks for all three fonts:

filmstrip-6 waterfall php-6

ndarville commented 8 years ago

For some reason, the loading of fonts.css is not deferred according to this waterfall:

screen shot 2015-11-23 at 20 56 41

(The blue line representing the DOM loading is on the left side of fonts.css.)

Compare to previously:

screen shot 2015-11-20 at 12 39 06

(The blue line is on the right side.)

OTOH, it looks like the DOM loading indicator is kinda wrong, seeing that nothing loaded beyond the DOM on the second timeline?

ndarville commented 8 years ago

Closing for now.