All Projects → joe-bell → Next Google Fonts

joe-bell / Next Google Fonts

Licence: mit
A tiny Next.js helper for loading Google Fonts fast and asynchronously ⏩

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Next Google Fonts

Graphcms Examples
Example projects to help you get started with GraphCMS
Stars: ✭ 295 (-20.05%)
Mutual labels:  nextjs
Heroku Nextjs
⏩ Deploy Next.js universal web apps to Heroku
Stars: ✭ 323 (-12.47%)
Mutual labels:  nextjs
Trpc
🧙‍♂️ TypeScript toolkit for building end-to-end typesafe APIs
Stars: ✭ 259 (-29.81%)
Mutual labels:  nextjs
Covid19 Brazil Api
API com dados atualizados sobre o status do COVID-19 🦠
Stars: ✭ 300 (-18.7%)
Mutual labels:  nextjs
Octoprofile
A nicer look at GitHub profiles built with Next.js and the GitHub API
Stars: ✭ 310 (-15.99%)
Mutual labels:  nextjs
Nextjs Tailwind Ionic Capacitor Starter
A starting point for building an iOS, Android, and Progressive Web App with Tailwind CSS, React w/ Next.js, Ionic Framework, and Capacitor
Stars: ✭ 315 (-14.63%)
Mutual labels:  nextjs
Hyper Site
The official website for the Hyper terminal
Stars: ✭ 289 (-21.68%)
Mutual labels:  nextjs
Apollo Upload Examples
A full stack demo of file uploads via GraphQL mutations using Apollo Server and apollo-upload-client.
Stars: ✭ 358 (-2.98%)
Mutual labels:  nextjs
Commerce
Next.js Commerce
Stars: ✭ 4,989 (+1252.03%)
Mutual labels:  nextjs
Woo Next
🚀 React WooCommerce theme, built with Next JS, Webpack, Babel, Node, Express, using GraphQL and Apollo Client
Stars: ✭ 342 (-7.32%)
Mutual labels:  nextjs
Jamstackthemes
A list of themes and starters for JAMstack sites.
Stars: ✭ 298 (-19.24%)
Mutual labels:  nextjs
Coderplanets web
the most sexiest community for developers, build with React, Mobx/MST, GraphQL, Styled-Components, Rxjs, Ramda ... and ❤️
Stars: ✭ 314 (-14.91%)
Mutual labels:  nextjs
Money Printer Go Brrr
Print it, baby!
Stars: ✭ 339 (-8.13%)
Mutual labels:  nextjs
Devii
A developer blog starter for 2020 (Next.js + React + TypeScript + Markdown + syntax highlighting)
Stars: ✭ 296 (-19.78%)
Mutual labels:  nextjs
Nest Next
Render Module to add Nextjs support for Nestjs
Stars: ✭ 348 (-5.69%)
Mutual labels:  nextjs
React Storefront
React Storefront - PWA for eCommerce. 100% offline, platform agnostic, headless, Magento 2 supported. Always Open Source, Apache-2.0 license. Join us as contributor ([email protected]).
Stars: ✭ 292 (-20.87%)
Mutual labels:  nextjs
Relate
[ARCHIVED] experimenting React + GraphQL + Next.js web app on the theme of mindfulness
Stars: ✭ 324 (-12.2%)
Mutual labels:  nextjs
Mxstbr.com
The source for my personal website
Stars: ✭ 370 (+0.27%)
Mutual labels:  nextjs
Shop
🛍🛒 Full-stack React/Prisma/TS/GraphQL E-Commerce Example
Stars: ✭ 359 (-2.71%)
Mutual labels:  nextjs
Next.js Typescript Starter Kit
🌳 [email protected], Styled-jsx, TypeScript, Jest, SEO
Stars: ✭ 342 (-7.32%)
Mutual labels:  nextjs

next-google-fonts

A tiny next/head helper for loading Google Fonts fast and asynchronously

NPM Version Types Included Minizipped Size MIT License NPM Downloads Follow @joebell_ on Twitter


Using Next.js 10? See "How does this compare to Next.js font optimization?" before continuing.

Table of Contents

  1. Setup
  2. FAQs

Setup

In this example, we're going to add Inter (specifically weights 400 and 700) to a Next.js app.

See joebell.co.uk for a working example.

  1. Add the package to your Next.js project:

    npm i next-google-fonts
    
  2. Create a custom Head component.

    It's important to acknowledge that next-google-fonts is a small next/head component and should not be nested inside next/head. To solve this, wrap both components with a Fragment.

    // components/head.js
    import * as React from "react";
    import NextHead from "next/head";
    import { GoogleFonts } from "next-google-fonts";
    
    export const Head = ({ children, title }) => (
      <React.Fragment>
        <GoogleFonts href="https://fonts.googleapis.com/css2?family=Inter:[email protected];700&display=swap" />
        <NextHead>
          <meta charSet="UTF-8" />
          <meta
            name="viewport"
            content="width=device-width, initial-scale=1.0"
          />
          <meta httpEquiv="x-ua-compatible" content="ie=edge" />
    
          <title>{title}</title>
    
          {children}
        </NextHead>
      </React.Fragment>
    );
    
  3. Add the requested Google Font/s to your styles with a sensible fallback. It really doesn't matter whether you're using CSS or Sass or CSS-in-JS:

    body {
      font-family: "Inter", sans-serif;
    }
    
  4. Run your Next.js app to see the results in action!

    You should expect to see the fallback font first, followed by a switch to the Google Font/s without any render-blocking CSS warnings. Your font/s will continue to display until your app is re-hydrated.

    If JS is disabled, only the fallback font will display.

FAQs

How does this compare to Next.js font optimization?

Next.js 10 introduced automatic Google Font optimization, you can make a decision on which solution to use based on the following criteria:

  • "My fonts are not priority and can be loaded asynchronously" - use next-google-fonts.
  • "My fonts are priority and should not be loaded asynchronously" - use Next.js font optimization.

For further reading, see the Next.js issue discussion.

Why?

next-google-fonts aims to make the process of using Google Fonts in Next.js more consistent, faster and painless: it preconnects to font assets, preloads and asynchronously loads the CSS file.

In the current iteration of next/head, we can't make use of the familiar "media hack" method of asynchronous Google font loading:

<!-- Plain HTML -->
<link
  rel="stylesheet"
  href="https://fonts.googleapis.com/css2?family=Inter:[email protected];700&display=swap"
  media="print"
  onload="this.media='all'"
/>

If you'd like to track this issue in Next.js, you can follow it here: Next.js#12984.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].