Recall & Review
beginner
What is compression middleware in Node.js?
Compression middleware is a tool that reduces the size of HTTP responses before sending them to the client. This helps pages load faster and saves bandwidth.
Click to reveal answer
beginner
How do you add compression middleware to an Express app?
You install the 'compression' package and then use it as middleware with app.use(require('compression')()). This compresses all responses automatically.
Click to reveal answer
intermediate
Which compression algorithms does the 'compression' middleware support by default?
It supports gzip and deflate compression algorithms by default, choosing the best one supported by the client browser.
Click to reveal answer
intermediate
Why should you be careful when compressing certain types of responses?
Some responses like images or already compressed files don't benefit from compression and can waste CPU time. Also, compressing very small responses may add overhead.
Click to reveal answer
advanced
How can you control which responses get compressed using compression middleware?
You can pass a filter function to the middleware options that checks the response type or size and returns true or false to decide if compression should happen.
Click to reveal answer
What does compression middleware do in a Node.js server?
✗ Incorrect
Compression middleware reduces the size of HTTP responses to speed up loading and save bandwidth.
Which package is commonly used for compression middleware in Express?
✗ Incorrect
The 'compression' package is the standard middleware for compressing responses in Express.
Which compression algorithms does the 'compression' middleware support by default?
✗ Incorrect
By default, the middleware supports gzip and deflate compression algorithms.
Why might you want to skip compressing images with compression middleware?
✗ Incorrect
Images are often already compressed formats like JPEG or PNG, so compressing them again wastes CPU without much benefit.
How can you customize which responses get compressed?
✗ Incorrect
You can provide a filter function to decide if a response should be compressed based on type or size.
Explain how compression middleware improves web performance and how to add it to an Express app.
Think about how smaller files travel faster over the internet.
You got /4 concepts.
Describe when and why you might want to exclude certain responses from compression.
Not all files benefit from compression equally.
You got /4 concepts.