Skip to content

[google_fonts] Support fetching WOFF2 font files via HTTP on web platforms #180998

Description

@Frank3K

Use case

When fonts are not bundled with the app, the google_fonts package fetches font files from the Google Fonts API. Currently, the URL is hard-coded to request .ttf files:

https://github.com/flutter/packages/blob/2e46240651cbd14d2b726d2fd46c8dcc13987fa2/packages/google_fonts/lib/src/google_fonts_descriptor.dart#L36-L51

This means web applications that rely on HTTP fetching (rather than bundling fonts) cannot benefit from the smaller file sizes and better compression that WOFF2 provides. WOFF2 files are typically 30-50% smaller than TTF files, which would improve load times for web applications.

Related PR: flutter/packages#10703 (adds for support for locally bundled fonts).

Proposal

Extend the HTTP font fetching logic to request WOFF2 files when running on web platforms:

  1. Update GoogleFontsDescriptor to support different file extensions based on platform
  2. On web, construct URLs that serve .woff2 files of .ttf

This would complement the upcoming WOFF2 support for bundled fonts, providing a complete solution for web platforms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.p: google_fontsPackage to use fonts from fonts.google.com. Supports HTTP fetching, caching, and asset bundling.packageflutter/packages repository. See also p: labels.platform-webWeb applications specificallyteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions