Skip to content

Commit

Permalink
perf(#41392): improve cache busting inject performance (#41443)
Browse files Browse the repository at this point in the history
The PR continues from #41392.

In #41392 the `dev ? cache-busting : empty` is executed per stylesheet instead of per page rendering. Since rendering link tags would be a hot path at the server, it might have accidentally introduced a performance overhead. The PR fixes that.

Note, this change also makes `Date.now()` only execute once instead of per stylesheets, however, this will most likely not cause any issues.
  • Loading branch information
SukkaW committed Oct 15, 2022
1 parent 482e3fb commit 85f7d4b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/next/server/app-render.tsx
Expand Up @@ -1165,6 +1165,10 @@ export async function renderToHTMLOrFlight(
Component: () => {
let props = {}

// Add extra cache busting (DEV only) for https://github.com/vercel/next.js/issues/5860
// See also https://bugs.webkit.org/show_bug.cgi?id=187726
const cacheBustingUrlSuffix = dev ? `?ts=${Date.now()}` : ''

return (
<>
{preloadedFontFiles.map((fontFile) => {
Expand All @@ -1184,9 +1188,7 @@ export async function renderToHTMLOrFlight(
? stylesheets.map((href) => (
<link
rel="stylesheet"
// Add extra cache busting (DEV only) for https://github.com/vercel/next.js/issues/5860
// See also https://bugs.webkit.org/show_bug.cgi?id=187726
href={`/_next/${href}${dev ? `?ts=${Date.now()}` : ''}`}
href={`/_next/${href}${cacheBustingUrlSuffix}`}
// `Precedence` is an opt-in signal for React to handle
// resource loading and deduplication, etc:
// https://github.com/facebook/react/pull/25060
Expand Down

0 comments on commit 85f7d4b

Please sign in to comment.