perf: More selective resource pre-fetching

This commit is contained in:
Tom Moor
2022-09-11 15:14:03 +01:00
parent 2c5b18c76b
commit 0587968f8b
5 changed files with 8 additions and 16 deletions

View File

@@ -32,7 +32,7 @@ import DocumentBreadcrumb from "./DocumentBreadcrumb";
const LazyLoadedEditor = React.lazy(
() =>
import(
/* webpackChunkName: "shared-editor" */
/* webpackChunkName: "preload-shared-editor" */
"~/editor"
)
);

View File

@@ -26,7 +26,7 @@ const SettingsRoutes = React.lazy(
const Document = React.lazy(
() =>
import(
/* webpackChunkName: "document" */
/* webpackChunkName: "preload-document" */
"~/scenes/Document"
)
);

View File

@@ -8,14 +8,14 @@ import { matchDocumentSlug as slug } from "~/utils/routeHelpers";
const Authenticated = React.lazy(
() =>
import(
/* webpackChunkName: "authenticated" */
/* webpackChunkName: "preload-authenticated" */
"~/components/Authenticated"
)
);
const AuthenticatedRoutes = React.lazy(
() =>
import(
/* webpackChunkName: "authenticated-routes" */
/* webpackChunkName: "preload-authenticated-routes" */
"./authenticated"
)
);

View File

@@ -3,7 +3,7 @@ import * as React from "react";
const MultiplayerEditor = React.lazy(
() =>
import(
/* webpackChunkName: "multiplayer-editor" */
/* webpackChunkName: "preload-multiplayer-editor" */
"./MultiplayerEditor"
)
);

View File

@@ -28,7 +28,6 @@ try {
// no-op
}
let index = 0;
Object.values(manifestData).forEach((filename) => {
if (typeof filename !== "string") {
return;
@@ -43,18 +42,11 @@ Object.values(manifestData).forEach((filename) => {
const shouldPreload =
filename.includes("/main") ||
filename.includes("/runtime") ||
filename.includes("/vendors");
// only prefetch the first few javascript chunks or it gets out of hand fast
const shouldPrefetch = ++index <= 6;
filename.includes("preload-");
if (shouldPreload || shouldPrefetch) {
if (shouldPreload) {
prefetchTags.push(
<link
rel={shouldPreload ? "preload" : "prefetch"}
href={filename}
key={filename}
as="script"
/>
<link rel="preload" href={filename} key={filename} as="script" />
);
}
} else if (filename.endsWith(".css")) {