From 31d3fa049dca7f5bf2f60b0b4b5b678a826966f2 Mon Sep 17 00:00:00 2001 From: Arne Luenser Date: Tue, 24 Mar 2026 15:16:03 +0100 Subject: [PATCH 1/2] feat: add Link HTTP headers for CSS bundle --- docusaurus.config.ts | 1 + src/plugins/preload-css.js | 54 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/plugins/preload-css.js diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 6b6185213..295267dca 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -151,6 +151,7 @@ const config: Config = { // buttonPosition: "center-right", // }, // ], + "./src/plugins/preload-css", async function tailwindcss(context, options) { return { name: "docusaurus-tailwindcss", diff --git a/src/plugins/preload-css.js b/src/plugins/preload-css.js new file mode 100644 index 000000000..e726fd70e --- /dev/null +++ b/src/plugins/preload-css.js @@ -0,0 +1,54 @@ +// Copyright © 2026 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + +const fs = require("fs") +const path = require("path") + +module.exports = function preloadCssPlugin() { + return { + name: "preload-css", + async postBuild({ outDir, siteConfig }) { + const cssDir = path.join(outDir, "assets", "css") + if (!fs.existsSync(cssDir)) return + + const cssFiles = fs.readdirSync(cssDir).filter((f) => f.endsWith(".css")) + if (cssFiles.length === 0) return + + const baseUrl = siteConfig.baseUrl.replace(/\/$/, "") + const linkValue = cssFiles + .map((f) => `<${baseUrl}/assets/css/${f}>; rel=preload; as=style`) + .join(", ") + + const vercelJsonPath = path.join(__dirname, "..", "..", "vercel.json") + const vercelJson = JSON.parse(fs.readFileSync(vercelJsonPath, "utf-8")) + + // Remove any existing preload header entries we previously added + vercelJson.headers = vercelJson.headers.filter( + (h) => + h.source !== "/docs/:path*" || + !h.headers.some((hh) => hh.key === "Link"), + ) + + // Add Link preload header for all doc pages + vercelJson.headers.push({ + source: "/docs/:path*", + headers: [ + { + key: "Link", + value: linkValue, + }, + ], + }) + + fs.writeFileSync( + vercelJsonPath, + JSON.stringify(vercelJson, null, 2) + "\n", + ) + + console.log( + "[preload-css] Updated vercel.json with %d CSS preload links", + cssFiles.length, + ) + }, + } +} From d254011d537414b371ff0074f8c0486740b0ef58 Mon Sep 17 00:00:00 2001 From: Arne Luenser Date: Tue, 24 Mar 2026 17:32:41 +0100 Subject: [PATCH 2/2] chore: ci job to update vercel.json --- .github/workflows/build.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a5e35a8ae..a2b304121 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,3 +22,12 @@ jobs: - run: npm install - name: Test Build run: npm run build + - name: Commit updated vercel.json + if: github.event_name == 'pull_request' + run: | + git diff --quiet vercel.json && exit 0 + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add vercel.json + git commit -m "chore: update CSS preload headers in vercel.json" + git push origin HEAD:${{ github.head_ref }}