Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

oderayi
Copy link

@oderayi oderayi commented Aug 10, 2019

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 the Accept-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.

@simonh1000 simonh1000 self-requested a review August 10, 2019 16:52
Copy link
Owner

@simonh1000 simonh1000 left a 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);
Copy link
Owner

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?

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);
Copy link
Owner

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?

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.

Copy link
Owner

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.

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.

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.

Copy link
Owner

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.

@simonh1000
Copy link
Owner

@oderayi can you provide some answers so that I can merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable compression
3 participants