kit icon indicating copy to clipboard operation
kit copied to clipboard

`precompress: true` ignores .txt files in the static folder

Open enda opened this issue 10 months ago • 1 comments

Describe the problem

When precompress: true is enabled, SvelteKit correctly generates .gz and .br files for most assets. However, plain text files (.txt) located in the static/ folder are completely ignored by the compression engine.

In production, common files like robots.txt or ads.txt are served uncompressed. For sites with strict performance requirements or those using gzip_static on in Nginx, this creates an inconsistency where these assets are either served without compression or require on-the-fly compression by the proxy, defeating the purpose of the precompress feature.

Describe the proposed solution

The pre-compression logic should be updated to include the .txt extension.

Specifically, in packages/kit/src/core/adapt/builder.js, the filter should be updated to ensure that .txt files from the static directory are picked up during the compression loop.

Since .txt files are highly compressible text-based assets, there is no technical reason to exclude them when other text formats like .xml or .svg are already included.

Alternatives considered

  • Manually running a post-build shell script to gzip / brotli the .txt files in build/client/.
  • Adding a third-party Vite plugin just to handle the missing .txt files, which adds unnecessary overhead to the dev stack.

Importance

nice to have

Additional Information

No response

enda avatar Jan 15 '26 10:01 enda

I wonder if that was done on purpose or if it should be an array of extensions to make it configurable. Adding the static and Node adapter tags because they both use the builder.compress API

teemingc avatar Jan 16 '26 16:01 teemingc