http-server: Why is .js.gz file not being served?
I gzipped my app.js
to app.js.gz
and then ran http-server -g
, as specified in the readme of this website.
But my browser still receives the .js file, not the .js.gz file, as you can see in the screenshot. Is this is a bug?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 6
- Comments: 22 (4 by maintainers)
@thescientist13 as I stated above, it worked if you generated your own
gz
files. The issue I was having was that if I enabled/passed a flag saying “turn gzip on”, I was expecting the server to do the gzip’ing on the fly. I’m fine with generating the files manually (now that I know that’s what I was supposed to do). It was just frustrating at the time since I wasted time thinking it was user error. Really what the--gzip
flag does, is say “if a gz version of a file exists, I’ll use that instead” - not “I’ll now gzip and serve specified file types”.I’m running
0.10.0
, looks like the gzip PR’s in there, but I’m still not seeing gzipped content come through. I’m runninghttp-server ./build --gzip -o -p 8080
.After reading through
ecstatic
’s docs, https://www.npmjs.com/package/ecstatic#optsgzip led me to what @RichardJECooke tried (to manually create a.gz
file). After doing so, I’m seeing that file served.The confusion seems to come from the fact that most servers that have a “simple setup” (and gzip is one of the available options), the server will do the work of gzipping for you (which is what I expected). This should really be called out in the docs to lessen confusion.
Possible solutions to anyone that come across this issue:
ecstatic
folks to update themiddleware
function to utilize the built inzlib
module so files get automagically served up gzipped.CompressionPlugin
to generate the.gz
files at build time with a configuration like thisThis does not work at all. .gz file created, -g and --gizp flag usdD. Only the .js loads. Altering <script> tag ref to .gz file, loads but won’t decompress.
This thread needs reopening
The
gzip
option has been introduced in b456b77, which has not been published to npm yet. You can check by runningnpm info http-server@latest gitHead
.You will have to wait until this is published or use
http-server@indexzero/http-server
(Git dependency).damnit, was also wondering why my gzip wasn’t working after looking at the code 😦
Great to hear @thescientist13!
I’d love some tests for this added, so we can be sure to avoid regressions. I’ll leave this open for anyone interested in sending a PR to improve the tests and/or README.
@the0neWhoKnocks I definitely agree we need to make this clearer in the docs. I’m not sure, though, that we should add any compression magic to the code–as it goes a bit against the whole static server thing. It would be good to have more docs and tests around this bit, so it’s more obvious how it works and what steps one needs to take to use it.