Skip to content

<Font preload /> generates excessive preload links #15841

Description

@myakura

Astro Info

Astro                    v6.0.2
Vite                     v7.3.1
Node                     v24.13.0
System                   macOS (arm64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

using <Font preload /> can produce a large number of <link rel="preload"> tags.

https://myakura.github.io/test--astro-v6-font-preloading/ (repo)

steps to observe:

  1. open index.html and check the <head> in DevTools — there are number of <link rel="preload"> tags
  2. open en.html — this page has only Latin content, but all preloads for the other pages are there, including Japanese unicode-range blocks the page will never render
  3. open ja.html — Noto Sans JP is a variable font on Google Fonts, but Astro requests separate files for each weight (400 and 700), roughly doubling the number of fetches

What's the expected result?

the current implementation appears to preload all font files unconditionally. so rather than improving performance, this likely makes it worse.
the problem is especially huge for languages like Japanese, Chinese, or other scripts that have many number of characters.

in an ideal situation

  • preload links should only be the ones actually cover characters used on the page
  • when a variable font is available (like Noto Sans JP or many others on Google Fonts), it should use as a variable font rather than splitting into separate per-weight files
  • there should be the cap of preload links. this should help if the number of preloads would still be many

i don't think that would be trivial, though... could the build emit a console warning when the number of generated preload links that is above a threshold? that would at least make it visible to developers that is not a great situation for performance.

Link to Minimal Reproducible Example

https://myakura.github.io/test--astro-v6-font-preloading/

Participation

  • I am willing to submit a pull request for this issue.

Activity

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

Metadata

Metadata

Labels

- P2: has workaroundAn edge case that only affects very specific usage, but has a trivial workaround (priority)needs responseIssue needs response from OPpkg: astroRelated to the core `astro` package (scope)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions