framework icon indicating copy to clipboard operation
framework copied to clipboard

Preload and self-host web fonts based on custom styles

Open mbostock opened this issue 2 years ago • 3 comments

#414 adds support for custom styles, ~~but we still hard-code the use of Google Fonts~~. We should ~~instead~~ transform the CSS bundle somehow to flatten external imports so that preloading is accurate.

mbostock avatar Dec 22 '23 17:12 mbostock

We likely want to introduce a google-fonts: protocol here so that users can control what’s self-hosted. It would be analogous to the self-hosting you get with npm:, versus when you link to https://cdn.jsdelivr.net/ to load the resource at runtime from an external website. So maybe this is self-hosted:

<link rel="stylesheet" href="google-fonts:/css2?family=Source+Serif+Pro:ital,wght@0,400;0,600;0,700;1,400;1,600;1,700&display=swap">

But this is hotlinked:

<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Source+Serif+Pro:ital,wght@0,400;0,600;0,700;1,400;1,600;1,700&display=swap">

mbostock avatar Mar 17 '24 18:03 mbostock

Does this need to be tied to the vendor? Or can we imagine calling this fonts:, with the vendor indicated elsewhere (in the configuration or in the URL rather than in the "protocol")?

e.g. <link rel="stylesheet" href="fonts:https://fonts.googleapis.com/css2?family=Source+Serif+Pro:ital,wght@0,400;0,600;0,700;1,400;1,600;1,700&display=swap">

or if we want shorthand:

<link rel="stylesheet" href="fonts:google/css2?family=Source+Serif+Pro:ital,wght@0,400;0,600;0,700;1,400;1,600;1,700&display=swap">

Fil avatar Mar 18 '24 10:03 Fil

This needs to be rethought after #1597 solved the main issue (i.e., that google fonts was hard-coded and prevented complete self-hosting); maybe it's just the same as #1573 now?

Fil avatar Aug 22 '24 15:08 Fil