Skip to content

Fonts consumption and distribution strategy #124

@huyenltnguyen

Description

@huyenltnguyen

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions