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

Fonts consumption and distribution strategy #124

Open
huyenltnguyen opened this issue May 9, 2024 · 0 comments
Open

Fonts consumption and distribution strategy #124

huyenltnguyen opened this issue May 9, 2024 · 0 comments
Assignees

Comments

@huyenltnguyen
Copy link
Member

huyenltnguyen commented May 9, 2024

Description

At the moment, we are having font files and fonts declaration in both the component library (this repo) as well as the library consumers (currently just /learn):

I'm looking into ways we can simplify the fonts management on the consumer end, ideally:

  • The consumers don't need to store the font files themselves
  • The consumers don't need to store a stylesheet for fonts declaration

Approaches

Options:

  1. Include the font files in the @freecodecamp/ui bundle, allowing downstream apps/packages to consume:
    import latoBold from '@freecodecamp/ui/dist/assets/fonts/lato/Lato-Bold.woff';
  2. Use the fonts from FontSource, in both @freecodecamp/ui and its downstream apps/packages. The fonts will be self-hosted, but FontSource manages the font files as well as handling the fonts declaration for us.
  3. Load the fonts from our CDN
  4. Load the fonts from a third-party CDN (mention for completeness, but I don't think this option is more performant, and there are also privacy implications)

Research

Since a lot of component libraries use Storybook, the Storybook projects page was my first stopping point, and I also looked at other component libraries that I know of / am familiar with.

Libraries that bundle fonts:

Libraries that promote loading fonts from FontSource:

Libraries that load fonts from their own CDN:

Conclusion

We usually want to load static assets from CDN for performance optimization, and this approach would help address the DX criteria mentioned above. However, I can't benchmark to be sure if / how the performance is improved.

As for choosing between bundling the fonts and using FontSource, it doesn't really matter because the approaches are essentially the same. We could move to FontSource if we want to reduce the code we have to house/maintain. But realistically, we don't have to touch the font files and fonts.css unless we need to change the fonts, so I think bundling the fonts ourselves is more straight-forward and would give us more control over our package.

I'll let others chime in on the CDN option. If we decide to not go with it, I think including fonts in the bundle should be the action item.

@huyenltnguyen huyenltnguyen self-assigned this May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant