Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure text remains visible during webfont load #5

Open
crock opened this issue Jun 2, 2020 · 8 comments
Open

Ensure text remains visible during webfont load #5

crock opened this issue Jun 2, 2020 · 8 comments
Labels
enhancement New feature or request

Comments

@crock
Copy link

crock commented Jun 2, 2020

image

The confirmed fix is to add display: swap; to each of the @font-face rules.

@3x 3x added the enhancement New feature or request label Jun 4, 2020
@au5ton
Copy link
Contributor

au5ton commented Jun 8, 2020

@crock @3x I submitted a PR involving this issue.

@3x 3x closed this as completed in 75f7b50 Jun 19, 2020
@mfilenko
Copy link
Contributor

Hey @crock,

Thanks a lot for spotting that!

Do you think swap is the only way to fix this problem or fallback can be a reasonable middle ground here?

As Guillermo Garron wrote (emphasis is mine):

I think the best ones are swap or fallback, swap is the best in render times, but the website flashes and visitors may find that annoying, on the other side, fallback has a small blocking time, but if the font takes to much time in loading, then the browser will not use it at all, and your website will endup using the system fonts.

I can imagine it's a tough choice: even though both options contribute to a better user experience, they do it differently (no invisible text vs no blinking text).

My suggestion with fallback is coming from an idea that 100 ms delay is something a human eye can tolerate :)

What do you guys think?

@au5ton
Copy link
Contributor

au5ton commented Jun 19, 2020

I haven't heard of fallback before but thank you for sharing more information about it!

Regarding its use in this repository, I'm not sure which method is objectively better. Its use of one vs the other seems situational. Personally, I prefer swap because I want to minimize render time. To me, when it comes to a repository that is dedicated to using webfonts it seems like swap is a good fit because (eventually) the intended font will swap.

Here are some additional resources on the font-display property:

@3x 3x reopened this Jun 19, 2020
@3x
Copy link
Member

3x commented Jun 19, 2020

I've merged #7, which adds swap to all fonts. This seems to be the best decision at the moment, per @au5ton's information, but I'm still open to changing this if it gives a better UX.

@mfilenko
Copy link
Contributor

@crock,

Would it be possible for you to re-run the diagnostics you did above, but this time with font-display: fallback to see if that warning still persists?

@au5ton
Copy link
Contributor

au5ton commented Jun 20, 2020

@mfilenko the diagnostic used above is: https://web.dev/measure/

@mfilenko
Copy link
Contributor

mfilenko commented Jul 1, 2020

Thanks! Checking...

@mfilenko
Copy link
Contributor

Hey guys,

I'm very sorry it took me that long to get back to you on this one!

Both swap and fallback options pass Lighthouse's audit, so I'd say it's up to @3x to choose a way to go :)

Even though I personally share Garron's approach to "use swap for icons, and fallback for the rest of web fonts", I'll be totally fine with either value. xz/fonts should be fast enough for this difference to be unnoticeable anyways ;)

I made this animation to illustrate how both options work:

87987899-af8d1d00-cadf-11ea-8ba8-fec8fabc1eb9(1)

As you can see a header uses swap which makes it 'flash'. The other two subheadings use fallback and they are being invisible for a short period of time (I simulated very slow connection for this demonstration).

While researching this issue I also noticed that Google Fonts CSS API uses display parameter to specify this property explicitly. I guess, if it becomes a deal breaker down the road we can just generate and serve different CSS files with different font-display values 🤔

For the time being I'm totally fine with closing this issue again 😅

Thank you for being patient and open to discussions!

Cheers,
Max

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants