perf(static): avoid filesystem lookups for missing public files - #11
Open
RomainLanz wants to merge 2 commits into
Open
RomainLanz wants to merge 2 commits into
RomainLanz wants to merge 2 commits into
Conversation
Static middleware probes public paths for application routes on every GET and HEAD request. Add an opt-in public directory index to skip known misses while preserving serve-static handling for possible hits. Index the whole directory instead of the Vite manifest so other public files remain accessible. Keep indexing disabled by default because new files require a process restart.
Skip the filesystem for paths ending with a slash when the directory has no index.html, so application routes such as "/" no longer probe the public directory. Fold index keys through lowercase before uppercase. Uppercasing alone reports existing files as missing for "ẞ" and "ϴ" on case-insensitive filesystems. Construct the middleware while booting the web environment so the scan does not delay the first request, and store keys relative to the public directory to reduce memory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The static middleware checks the filesystem for every GET and HEAD request, including application routes that have no matching public file.
This adds an opt-in
indexFilesoption. The middleware indexespublic/once when constructed and passes missing paths directly to the next middleware. A public directory index also covers files outside the Vite manifest, such asrobots.txt.Existing files still use
serve-staticfor metadata, caching, HEAD, ranges, directory handling, and dotfile rules. Symlink descendants and case variants also delegate toserve-static.The default remains unchanged. Indexing is intended for immutable deployments. Adding files requires a restart; leave it disabled for development and uploads. The index requires a synchronous initial scan and memory proportional to the public directory size.
Verification:
npm test: 19 passed, including lint.npm run typecheckandnpm run build: passed.This removes negative filesystem probes, not existing asset reads. Warm read_bytes remained zero with and without indexing, so these tests do not establish physical disk savings or a fixed throughput gain.