What is the preferred way of including Google Fonts on a page?
<link>
tag
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Judson:ital,wght@0,400;0,700;1,400&display=swap" rel="stylesheet">
@import url('https://fonts.googleapis.com/css2?family=Kameron:wght@400;700&display=swap');
For 90%+ of the cases you likely want the <link>
tag. As a rule of thumb, you want to avoid @import
rules because they defer the loading of the included resource until the file is fetched.. and if you have a build process which "flattens" the @import's, then you create another problem with web fonts: dynamic providers like Google WebFonts serve platform-specific versions of the fonts, so if you simply inline the content, then you'll end up with broken fonts on some platforms.
Now, why would you use the web font loader? If you need complete control over how the fonts are loaded. Most browsers will defer painting the content to the screen until all of the CSS is downloaded and applied - this avoids the "flash of unstyled content" problem. The downside is.. you may have an extra pause and delay until the content is visible. With the JS loader, you can define how and when the fonts become visible.. for example, you can even fade them in after the original content is painted on the screen.
Once again, the 90% case is the <link>
tag: use a good CDN and the fonts will come down quick and even more likely, be served out of the cache.
For more info, and an in-depth look at Google Web Fonts, check out this GDL video