Skip to content

Commit 33c9f42

Browse files
ChengaDevclaude
andcommitted
Improve LCP: preload clock font, async-load external CSS
- Move DSEG14 font to public/fonts/ and declare @font-face in index.html so it can be preloaded before React renders - Add font-display: swap so browser renders fallback instantly - Load FontAwesome and Google Fonts asynchronously via rel=preload + onload trick — no longer render-blocking - Add preconnect hints for fonts.googleapis.com / fonts.gstatic.com - Remove duplicate @font-face from App.tsx GlobalStyle Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 85eaba9 commit 33c9f42

4 files changed

Lines changed: 33 additions & 10 deletions

File tree

14.6 KB
Binary file not shown.

public/index.html

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,43 @@
5656
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"
5757
></script>
5858
<title>ShotClock Pro - Basketball Shot Clock Training</title>
59+
<!-- Preload clock font so it's ready before React renders the display -->
60+
<link rel="preload" href="/fonts/DSEG14ClassicRegular.ttf" as="font" type="font/ttf" crossorigin="anonymous" />
61+
<style>
62+
@font-face {
63+
font-family: 'DSEG14ClassicRegular';
64+
src: url('/fonts/DSEG14ClassicRegular.ttf') format('truetype');
65+
font-weight: normal;
66+
font-style: normal;
67+
font-display: swap;
68+
}
69+
</style>
70+
71+
<!-- FontAwesome — load async, don't block render -->
5972
<link
60-
rel="stylesheet"
73+
rel="preload"
6174
href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css"
75+
as="style"
6276
integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p"
6377
crossorigin="anonymous"
78+
onload="this.rel='stylesheet'"
79+
/>
80+
<noscript>
81+
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous" />
82+
</noscript>
83+
84+
<!-- Google Fonts — load async, don't block render -->
85+
<link rel="preconnect" href="https://fonts.googleapis.com" />
86+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="anonymous" />
87+
<link
88+
rel="preload"
89+
href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap"
90+
as="style"
91+
onload="this.rel='stylesheet'"
6492
/>
65-
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap" rel="stylesheet" />
93+
<noscript>
94+
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap" rel="stylesheet" />
95+
</noscript>
6696
<style>
6797
body {
6898
font-family: 'Roboto', sans-serif !important;

src/App.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import Footer from './components/Footer'
88
import CookieBanner from './components/CookieBanner'
99
import { lightTheme, darkTheme } from './themes/themes'
1010
import { createGlobalStyle } from 'styled-components'
11-
import './assets/fonts/dseg14/dseg14.css'
1211
import { useSpring, animated } from 'react-spring'
1312
import Themes from './constants/Themes'
1413

@@ -169,13 +168,6 @@ const App = () => {
169168
}
170169

171170
const GlobalStyle = createGlobalStyle`
172-
@font-face {
173-
font-family: 'DSEG14ClassicRegular';
174-
src: url('./assets/fonts/dseg14/DSEG14ClassicRegular.ttf') format('truetype');
175-
font-weight: normal;
176-
font-style: normal;
177-
}
178-
179171
body {
180172
margin: 0;
181173
padding: 0;

src/assets/fonts/dseg14/dseg14.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
src: url('./DSEG14ClassicRegular.ttf') format('truetype');
44
font-weight: normal;
55
font-style: normal;
6+
font-display: swap;
67
}

0 commit comments

Comments
 (0)