From c8c6d9132af77965d95c91573a974724b949d80f Mon Sep 17 00:00:00 2001 From: 134 Date: Mon, 13 Jul 2026 17:33:02 +0800 Subject: [PATCH] perf: precompress HiCAD frontend assets --- deploy/nginx-hicad-zoo-ws.conf.template | 1 + scripts/vendor-zoo-modeling-app.mjs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/deploy/nginx-hicad-zoo-ws.conf.template b/deploy/nginx-hicad-zoo-ws.conf.template index efadff030..2d10cda7b 100644 --- a/deploy/nginx-hicad-zoo-ws.conf.template +++ b/deploy/nginx-hicad-zoo-ws.conf.template @@ -4,6 +4,7 @@ location ^~ /vendor/zoo-modeling-app/assets/ { root /var/www/ai-chatbot/public; try_files $uri =404; + gzip_static on; add_header Cache-Control "public, max-age=31536000, immutable" always; } diff --git a/scripts/vendor-zoo-modeling-app.mjs b/scripts/vendor-zoo-modeling-app.mjs index c5fa34c8b..33a0b12c5 100644 --- a/scripts/vendor-zoo-modeling-app.mjs +++ b/scripts/vendor-zoo-modeling-app.mjs @@ -5,12 +5,14 @@ import { copyFileSync, existsSync, mkdirSync, + readdirSync, readFileSync, rmSync, writeFileSync, } from "node:fs"; import { cp } from "node:fs/promises"; import path from "node:path"; +import { gzipSync } from "node:zlib"; const repoUrl = "https://github.com/KittyCAD/modeling-app.git"; const repoRef = @@ -298,6 +300,17 @@ function ensureWasm() { copyFileSync(wasmBinary, path.join(sourceDir, "public/kcl_wasm_lib_bg.wasm")); } +function precompressVersionedAssets() { + const assetsDir = path.join(outputDir, "assets"); + for (const entry of readdirSync(assetsDir, { withFileTypes: true })) { + if (!entry.isFile() || !/\.(?:css|js)$/.test(entry.name)) { + continue; + } + const assetPath = path.join(assetsDir, entry.name); + writeFileSync(`${assetPath}.gz`, gzipSync(readFileSync(assetPath), { level: 9 })); + } +} + async function main() { ensureOfficialSource(); ensureDependencies(); @@ -329,6 +342,7 @@ async function main() { rmSync(outputDir, { force: true, recursive: true }); mkdirSync(path.dirname(outputDir), { recursive: true }); await cp(buildDir, outputDir, { recursive: true }); + precompressVersionedAssets(); const license = path.join(sourceDir, "LICENSE"); if (existsSync(license)) {