Unverified Commit 85f7d4b3 authored by Sukka's avatar Sukka Committed by GitHub

perf(#41392): improve cache busting inject performance (#41443)

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.
parent 482e3fbf
...@@ -1165,6 +1165,10 @@ export async function renderToHTMLOrFlight( ...@@ -1165,6 +1165,10 @@ export async function renderToHTMLOrFlight(
Component: () => { Component: () => {
let props = {} 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 ( return (
<> <>
{preloadedFontFiles.map((fontFile) => { {preloadedFontFiles.map((fontFile) => {
...@@ -1184,9 +1188,7 @@ export async function renderToHTMLOrFlight( ...@@ -1184,9 +1188,7 @@ export async function renderToHTMLOrFlight(
? stylesheets.map((href) => ( ? stylesheets.map((href) => (
<link <link
rel="stylesheet" rel="stylesheet"
// Add extra cache busting (DEV only) for https://github.com/vercel/next.js/issues/5860 href={`/_next/${href}${cacheBustingUrlSuffix}`}
// See also https://bugs.webkit.org/show_bug.cgi?id=187726
href={`/_next/${href}${dev ? `?ts=${Date.now()}` : ''}`}
// `Precedence` is an opt-in signal for React to handle // `Precedence` is an opt-in signal for React to handle
// resource loading and deduplication, etc: // resource loading and deduplication, etc:
// https://github.com/facebook/react/pull/25060 // https://github.com/facebook/react/pull/25060
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment