Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Further optimize fonts and styles #27902

Closed
ctjlewis opened this issue Aug 9, 2021 · 0 comments
Closed

Feature request: Further optimize fonts and styles #27902

ctjlewis opened this issue Aug 9, 2021 · 0 comments

Comments

@ctjlewis
Copy link
Contributor

ctjlewis commented Aug 9, 2021

Describe the feature you'd like to request

(Reposting as an issue because I sent directly to discussions, forgetting that we want them to flow through issues first. TY for patience with all my recent PRs and feature requests.)

The current font optimization logic definitely saves the client a step when using Google Fonts—needing only to pull font data directly from fonts.gstatic.com, no need to load stylesheets from fonts.googleapis.com, which are injected directly into the page—but it still blocks the render because the embedded styles are not deferred.

The defer attribute should be applied to all embedded <style> attributes; <script> elements are properly marked defer and do not block render based on the output I have reviewed.

Originally posted by @ctjlewis in #27866

Describe the solution you'd like

  1. Remove unnecessary <link data-href="..."> tags following optimization.

  2. All <style> tags, including those emitted by font optimization, should be marked defer to avoid blocking the first paint.

  3. Nodes which render <link> elements should also be optimized. Currently only direct <link> elements are modified.

    3.1. Add <GoogleFont> component to next/head: https://gist.github.com/ctjlewis/1a9ee9cac89b8b87fc97c02c28f0f2d0

  4. Default to lang="en" for <Html> component over undefined. Templates are English by default, so this is an appropriate default.

  5. Resolve issues related to testing a local development version of the Next.js CLI.

    I would implement these optimization changes myself and send a PR in (which I tried to get started on), except nondeterministic behavior occurs when running next build where "next": "/path/to/development/next" is set in package.json, and it was impossible to develop locally and live-test features related to production optimization.

    See: Contributing: Local next build failing #27826

Results

Making these changes (currently by manually modifying the output, since a local dev version of the CLI cannot run next build on my machine, see 5 above), I was able to get a perfect Lighthouse score for the default starter (though there are design bugs present which break the viewport on small screens and could be fixed while we're "in the area", see #24709).

@vercel vercel locked and limited conversation to collaborators Aug 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants