Skip to content

Commit cad977e

Browse files
authored
impr: use preload for vendor.css and fonts (@fehmer) (monkeytypegame#6234)
!nuf
1 parent 8c20b6c commit cad977e

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"sass": "1.70.0",
5959
"subset-font": "2.3.0",
6060
"typescript": "5.5.4",
61+
"unplugin-inject-preload": "3.0.0",
6162
"vite": "6.0.11",
6263
"vite-bundle-visualizer": "1.0.1",
6364
"vite-plugin-checker": "0.7.2",

frontend/src/html/head.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
<head>
2+
<link
3+
rel="preload"
4+
href="/webfonts/RobotoMono-Regular.woff2"
5+
type="font/woff2"
6+
as="font"
7+
crossorigin
8+
/>
9+
<link
10+
rel="preload"
11+
href="/webfonts/LexendDeca-Regular.woff2"
12+
type="font/woff2"
13+
as="font"
14+
crossorigin
15+
/>
16+
217
<script>
318
document.addEventListener("keydown", function (e) {
419
if (e.key == "Escape") e.preventDefault();
@@ -89,7 +104,6 @@
89104
<meta name="twitter:card" content="summary_large_image" />
90105
<meta name="darkreader-lock" />
91106
<meta http-equiv="Cache-Control" content="no-store" />
92-
<link rel="preload" href="styles/vendor.scss" as="style" />
93107
<link rel="stylesheet" href="styles/vendor.scss" />
94108
<link rel="stylesheet" href="styles/index.scss" />
95109
</head>

frontend/vite.config.prod.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { splitVendorChunkPlugin } from "vite";
88
import childProcess from "child_process";
99
import { checker } from "vite-plugin-checker";
1010
import { writeFileSync } from "fs";
11+
// eslint-disable-next-line import/no-unresolved
12+
import UnpluginInjectPreload from "unplugin-inject-preload/vite";
1113

1214
function pad(numbers, maxLength, fillString) {
1315
return numbers.map((number) =>
@@ -84,6 +86,7 @@ export default {
8486
splitVendorChunkPlugin(),
8587
VitePWA({
8688
// injectRegister: "networkfirst",
89+
injectRegister: "script-defer",
8790
registerType: "autoUpdate",
8891
manifest: {
8992
short_name: "Monkeytype",
@@ -143,6 +146,29 @@ export default {
143146
},
144147
},
145148
]),
149+
UnpluginInjectPreload({
150+
files: [
151+
{
152+
outputMatch: /css\/vendor.*\.css$/,
153+
attributes: {
154+
as: "style",
155+
type: "text/css",
156+
rel: "preload",
157+
crossorigin: true,
158+
},
159+
},
160+
{
161+
outputMatch: /.*\.woff2$/,
162+
attributes: {
163+
as: "font",
164+
type: "font/woff2",
165+
rel: "preload",
166+
crossorigin: true,
167+
},
168+
},
169+
],
170+
injectTo: "head-prepend",
171+
}),
146172
],
147173
build: {
148174
emptyOutDir: true,

pnpm-lock.yaml

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)