0
0
Node.jsframework~5 mins

Compression middleware in Node.js - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AReduces the size of HTTP responses before sending
BEncrypts the HTTP responses
CCaches the HTTP responses
DLogs the HTTP requests
Which package is commonly used for compression middleware in Express?
Aexpress-compress
Bbody-parser
Ccompression
Dmorgan
Which compression algorithms does the 'compression' middleware support by default?
Agzip and deflate
Bbrotli only
Clzma and bzip2
Dzip only
Why might you want to skip compressing images with compression middleware?
ACompression middleware does not work on images
BImages are already compressed and compressing again wastes CPU
CImages cannot be compressed
DImages load faster uncompressed
How can you customize which responses get compressed?
ABy disabling compression globally
BBy changing the server port
CBy modifying the request headers
DBy setting a filter function in middleware options
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.