Skip to content

Boost: Preload fonts #20566

Open
Open

Description

originally filed by @gravityrail

PageSpeed detected opportunities to improve load speed by preloading fonts.

In this particular case, adding the following to a test plugin improved scores.

add_action( 'wp_head', function() {
echo '<link rel="preload" href="https://boosttest.mystagingwebsite.com/wp-content/themes/uncode/library/fonts/uncode-icons.woff2" as="font" type="font/woff2" crossorigin/>';
}, -PHP_INT_MAX );

We can/should use the Lighthouse results themselves to "discover" which fonts can/should be preloaded on a given URL. Note the type and crossorigin attributes are required if the font is served from a CDN.

Separately we may want to modify CSS to serve fonts from the origin. Browsers now typically segment caches by origin anyway so there's no caching benefit to having a shared instance, and incurring the DNS cost may cancel out any CDN benefits.

Some initial exploration notes in the old repo in a comment here: 664-gh-Automattic/jetpack-boost

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

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions