Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google fonts loading optimisation and caching

Google's page speed test shows only one problem:

Eliminate render-blocking JavaScript and CSS in above-the-fold content Your page has 1 blocking CSS resources. This causes a delay in rendering your page.
None of the above-the-fold content on your page could be rendered without waiting for the following resources to load. Try to defer or asynchronously load blocking resources, or inline the critical portions of those resources directly in the HTML.
Optimize CSS Delivery of the following:
https://fonts.googleapis.com/css?family=Roboto:300,400

The fonts being loaded as fonts.google.com recommends:

<link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet">

Within <head /> tag.

As far as i know, there is no way to control google's fonts caching and also, this url's output depends on user agent, so it doesn't make sense to distribute the fonts locally. So, the question is: what do i suppose to do with that? How do i satisfy google's speed test?

like image 607
stkvtflw Avatar asked Oct 30 '22 07:10

stkvtflw


1 Answers

So far i know ist the best solution today if you use Fontloader. It loads first a short .js script and late the font async.
Tipp: Use font-family: 'Roboto', 'sans serif'; async has the problem the font type is switching after the site is rendered. So the user see a short font switch like a flash. If you use sans serif as fallback the switch is not so big.
Or use .wf-active

like image 156
Lovntola Avatar answered Nov 09 '22 07:11

Lovntola