Skip to content

Commit f2ad6d4

Browse files
committed
impr: use preload for vendor.css and fonts (@fehmer)
1 parent 12e1500 commit f2ad6d4

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<head>
2+
<link rel="preload" href="/webfonts/RobotoMono-Regular.woff2" type="font/woff2" as="font" crossorigin />
3+
<link rel="preload" href="/webfonts/LexendDeca-Regular.woff2" type="font/woff2" as="font" crossorigin />
4+
25
<script>
36
document.addEventListener("keydown", function (e) {
47
if (e.key == "Escape") e.preventDefault();
@@ -89,7 +92,6 @@
8992
<meta name="twitter:card" content="summary_large_image" />
9093
<meta name="darkreader-lock" />
9194
<meta http-equiv="Cache-Control" content="no-store" />
92-
<link rel="preload" href="styles/vendor.scss" as="style" />
9395
<link rel="stylesheet" href="styles/vendor.scss" />
9496
<link rel="stylesheet" href="styles/index.scss" />
9597
</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)