There are many reasons to self-host Google Fonts. For me, the privacy-aspect is most important. Thanks to Acorn v2.x and spatie/laravel-google-fonts, self-hosting Google Fonts is a breeze.
1. Install spatie/laravel-google-fonts
composer require spatie/laravel-google-fonts
2. Add serviceprovider in themename/config/app.php (providers section). Spatie\GoogleFonts\GoogleFontsServiceProvider::class,
If the app.php file is not present in the config directory, you need to publish it: wp acorn vendor:publish --tag=acorn
spatie/laravel-google-fonts provides a directive for adding this CSS, but as index.php is a regular PHP file, directives won’t work in this file.
That’s about it. First time you load your website, it will fetch the fonts and place theme in /app/fonts. You can fetch the fonts from command line with following command: wp acorn google-fonts:fetch
The idea of spatie’s google fonts is that you won’t need to use the font link client side or google domain, so you don’t need the preconnect. It connects and downloads on the server the first time you request it. And keeps it up to date.
I wonder if it can be added when the fallback is used and only when it is used though.
I always use the ‘Google webfont helper’ which allows you to download the fonts and use them in your theme folder. That seems a bit easier than using PHP for this.