Skip to content

Conversation

@Frank3K
Copy link
Contributor

@Frank3K Frank3K commented Jan 2, 2026

Description

Web applications benefit significantly from using WOFF2 font files instead of TTF/OTF. WOFF2 is a compressed format
specifically designed for web delivery, resulting in smaller file sizes and faster load times. This is especially
important for Flutter web apps where every byte counts for initial page load performance.

Size comparison (Roboto Regular):

  • TTF: 146,004 bytes
  • WOFF2: 63,424 bytes (~56% smaller)

Currently, google_fonts only supports TTF and OTF formats, even on web platforms where WOFF2 would be more efficient.
This PR adds support for WOFF2 and WOFF formats on web, allowing developers to bundle more efficient font files for their
web applications.

What

This PR adds support for .woff2 and .woff font file extensions when running on web platforms, while maintaining
backward compatibility with .ttf and .otf files.

Changes:

  • Add kIsWeb check to support web-optimized font formats (.woff2, .woff) in addition to .ttf and .otf
  • Make findFamilyWithVariantAssetPath testable by adding an optional isWeb parameter (defaults to kIsWeb)
  • Add @visibleForTesting annotation to enable comprehensive testing without exposing internal API
  • Add 20 tests covering web-specific, non-web-specific, and common behavior

Platform behavior:

  • Web: Supports .woff2, .woff, .ttf, .otf
  • Non-web: Supports .ttf, .otf (unchanged)

Implementation Notes

The implementation maintains the existing behavior where the order of assets in the manifest determines which file type
is chosen
when multiple formats are available for the same font. While this feels a bit odd (ideally, there would be a
preference order), this is how the function already works for TTF/OTF. In practice, this is not an issue when only one
file type per font is bundled, which is the common case.

Getting WOFF2 Files

Developers can convert TTF/OTF fonts to WOFF2 using Google's woff2_compress tool:
https://github.com/google/woff2

Example:

woff2_compress Roboto-Regular.ttf

Testing

All existing tests pass, plus 20 new tests that verify:

  • ✅ WOFF2 and WOFF formats work on web
  • ✅ WOFF2 and WOFF formats are ignored on non-web platforms
  • ✅ TTF and OTF continue to work on all platforms
  • ✅ Common behavior (null handling, family/variant matching) works consistently

Breaking Changes

None. This is a backward-compatible addition that only expands the supported file formats on web platforms.
EOF

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

Adds support for WOFF and WOFF2 font formats when running on web platforms,
in addition to the existing TTF and OTF support. This improves web performance
as WOFF2 is a more compressed format optimized for web delivery.

Non-web platforms continue to support only .ttf and .otf.
@Frank3K Frank3K requested a review from Piinks as a code owner January 2, 2026 06:12
@github-actions github-actions bot added p: google_fonts triage-framework Should be looked at in framework triage labels Jan 2, 2026
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for WOFF and WOFF2 font formats on the web, which is a great performance improvement due to smaller file sizes. The changes are well-implemented, introducing a check for kIsWeb to conditionally allow the new formats. The findFamilyWithVariantAssetPath function has been thoughtfully refactored to be testable, and the new tests are comprehensive, covering web, non-web, and common scenarios. The decision to maintain the existing asset selection logic based on manifest order to ensure backward compatibility is sensible. Overall, this is a high-quality contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: google_fonts triage-framework Should be looked at in framework triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant