Skip to content

Dev server should send pre-compressed static files without Content-Encoding: gzip #12266

@mz8i

Description

@mz8i

Description

I am serving some pre-compressed .csv.gzip files from the public directory.

The dev server automatically serves these with Content-Type: text/csv and Content-Encoding: gzip.

This seems somewhat overzealous, especially when the requested file explicitly has a .csv.gzip extension and the client code expects the content it receives to be compressed.

The problem is mostly that this doesn't seem to be configurable, which leads to inconsistencies when later deploying to sites without such a behaviour. Consider that GitHub Pages sends the same files as Content-Type: application/gzip which is definitely less unexpected.

For example, I ran into this issue because it turned out that my code was not decompressing the CSV files correctly, but I only realised this after deploying to a server because locally I didn't realise the browser was actually doing the decompression based on Content-Encoding. Now, I know that a lot of hosting services like GH Pages gzip content automatically and send it with Content-Encoding so that the compression is transparent to user code, but when the user specifically requests files that are hosted pre-compressed, the services usually don't interfere, and I think Vite dev server should act the same way.

I personally think this should not be the default behaviour, but at least should be possible to turn off.

Suggested solution

Change the default behaviour to not set Content-Encoding: gzip and Content-Type: [...] but rather send as Content-Type: application/gzip for files that are stored as already compressed.

Alternative

Expose a server configuration toggle to allow for turning the current behaviour off.

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions