mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #398] [CLOSED] perf: async static file serving and precompressed hashed assets #543
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#543
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/398
Author: @NathanDrake2406
Created: 3/10/2026
Status: ❌ Closed
Base:
main← Head:perf/prod-server-static-serving📝 Commits (2)
aa2d475perf: async static file serving and precompressed hashed assets7cf552atest: add tests for precompressAssets and async tryServeStatic📊 Changes
2 files changed (+249 additions, -9 deletions)
View changed files
📝
packages/vinext/src/server/prod-server.ts(+124 -9)📝
tests/features.test.ts(+125 -0)📄 Description
Summary
existsSync+statSyncintryServeStaticwithfs.promises.stat— stops blocking the event loop on every static file requestprecompressAssets()runs at startup, brotli (q11) + gzip (l9) compresses all compressible files underassets/into an in-memory map. Hashed asset requests serve these buffers directly instead of re-compressing per hitContent-Lengthfrom the stat resultDetails
The Node.js prod server was doing two expensive things on every static file request:
Sync filesystem probes —
existsSync+statSyncblock the event loop. Replaced with a single asyncfsp.stat()that catches ENOENT.Per-request compression of immutable assets — Files under
/assets/have content hashes andCache-Control: immutable, yet were re-compressed with brotli/gzip on every request. Now compressed once at startup with max compression settings (brotli q11, gzip l9) since the cost is amortized. The compressed buffers are served directly viares.end(buf)— no streaming compressor needed.Non-hashed assets (e.g.
favicon.ico) still use on-the-fly compression as before.Test plan
precompressAssetscompresses JS/CSS above size thresholdprecompressAssetsskips files below thresholdprecompressAssetsreturns empty map for missingassets/directoryprecompressAssetsskips non-compressible types (images)tryServeStaticserves precompressed brotli buffer for hashed assetstryServeStaticreturns false for non-existent files via async stat🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.