-
Notifications
You must be signed in to change notification settings - Fork 41
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
Add support for deflate and gzip compression #31
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of questions. I tested it at it seems to work for my simple test environment
closes #26
res.writeHead(200, { | ||
"Content-Type": ct | ||
}); | ||
raw.pipe(res); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain what raw.pipe does relative the existing code that uses res.write?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@simonh1000, the pipe here allows the file that is being read as a stream to be streamed directly to the response without the entire file being in memory at any point. It is a more efficient approach to serving files, especially if any of the static assets is large.
}); | ||
raw.pipe(zlib.createDeflate()).pipe(res); | ||
} else { | ||
log("Unsupported encoding: ", encoding); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we hit this will a server request being going unanswered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@simonh1000, that is my read.
If you'd like, I can pick this up and carry it to the finish line, including handling unsupported encodings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd first like to understand why this feature is useful for people on this development-only server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a fair question. I'm not entirely sure myself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like @oderayi's use case was Lighthouse auditing before deploying to production.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm. auditing like this does not help you know what score you will get in production. I'm concerned that this is increasing the sense that this is a production server, which it absolutely is not. I'm inclined to drop this.
@oderayi can you provide some answers so that I can merge? |
closes: #26
This change is to add compression (gzip and deflate) support for content
['application/javascript', 'application/json', 'text/html', 'text/css']
automatically (without a command line switch) based on theAccept-Encoding
request header entry.Didn't have much time to write the tests but, my instinct tells me it works. Might need a bit of optimization here and there.