Skip to content

Commit

Permalink
load font properly to avoid CLS
Browse files Browse the repository at this point in the history
  • Loading branch information
Holtz Yan authored and Holtz Yan committed Aug 1, 2023
1 parent 86f9276 commit 839f0b6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
12 changes: 0 additions & 12 deletions component/HeadSeo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ export const HeadSeo = ({ title, seoDescription }: HeadSeoProps) => {
sizes="16x16"
href="/favicon/favicon-16x16.png"
/>

{/* Load fonts. Then used in style.css */}
<link
href="https://fonts.googleapis.com/css2?family=Fira+Code&family=Roboto+Mono:wght@300&display=swap"
rel="stylesheet"
/>
{/* Bitter AND roboto in 1 shot */}
<link
href="https://fonts.googleapis.com/css2?family=Bitter:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800&family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap"
rel="stylesheet"
></link>

<meta
name="keywords"
content="React, D3, D3.js, data, dataviz, data visualization, DOM, web, dev, chart, graph"
Expand Down
16 changes: 16 additions & 0 deletions fonts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This is where I load my fonts
// Read https://nextjs.org/docs/pages/building-your-application/optimizing/fonts
// Fonts are downloaded at build time
// Users won't make a call to google when using the website
import { Bitter, Roboto } from 'next/font/google';

export const inter = Bitter({
subsets: ['latin'],
display: 'swap',
});

export const roboto = Roboto({
weight: ['300', '500', '700'],
subsets: ['latin'],
display: 'swap',
});
10 changes: 5 additions & 5 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import "tailwindcss/tailwind.css";
import "../style/style.css";
import type { AppProps } from "next/app";
import Script from "next/script";
import "../style/prism.css";
import 'tailwindcss/tailwind.css';
import '../style/style.css';
import type { AppProps } from 'next/app';
import Script from 'next/script';
import '../style/prism.css';

function MyApp({ Component, pageProps }: AppProps) {
return (
Expand Down
2 changes: 0 additions & 2 deletions style/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ body {
font-size: 19px;
line-height: 30px;
color: #333;
/* Trying to load fonts better to solve CLS issue */
font-display: optional;
}

p {
Expand Down

0 comments on commit 839f0b6

Please sign in to comment.