-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dev server should send pre-compressed static files without Content-Encoding: gzip
#12266
Comments
I was also tripped by this behavior. See this question on StackOverflow. |
Ran into the same issue. Our application uses JS |
Is the issue with It would be nice to fix the issue upstream fix, before needing Vite to patch it. |
It's been a while since I originally ran into this, but if my original description is to be trusted, I encountered this with |
I don't think so based on https://github.com/lukeed/sirv/blob/50b1964b8a8342e14a711d47f793298c2a7aeeb7/packages/sirv/index.js#L95 (also tested locally) |
Experiencing this with .gz. The CDN serves these files differently so the dev environment gets the content auto gunzipped by the browser but in production it's crashing. |
FYI, I just attempted a PR on upstream to fixed this lukeed/sirv#161. Upstream fix is a little more involved, but if Vite needs to fix this for own usage, then it would be a one liner to comment out |
Description
I am serving some pre-compressed
.csv.gzip
files from thepublic
directory.The dev server automatically serves these with
Content-Type: text/csv
andContent-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 withContent-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
andContent-Type: [...]
but rather send asContent-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
The text was updated successfully, but these errors were encountered: