An ETag (Entity Tag) is a unique identifier assigned by a server to a specific version of a resource. It helps browsers know if the resource has changed since the last time it was fetched.
Click to reveal answer
beginner
How does a conditional request use an ETag?
A client sends the ETag it has in the 'If-None-Match' header. The server compares it with the current ETag. If they match, the server replies with 304 Not Modified, saving bandwidth by not sending the full resource again.
Click to reveal answer
beginner
Which HTTP status code indicates the resource has not changed when using ETag conditional requests?
The status code 304 Not Modified means the resource has not changed and the client can use its cached version.
Click to reveal answer
intermediate
In Node.js, which module is commonly used to handle ETag generation and conditional requests?
The 'http' module can be used directly, but frameworks like Express.js provide middleware (e.g., 'etag' middleware) to automatically generate and check ETags for responses.
Click to reveal answer
beginner
Why are ETags useful for improving web performance?
ETags reduce unnecessary data transfer by letting clients know if their cached copy is still valid. This saves bandwidth and speeds up page loads by avoiding full downloads when content hasn't changed.
Click to reveal answer
What header does a client send to perform a conditional request using an ETag?
AIf-Match
BIf-None-Match
CETag
DCache-Control
✗ Incorrect
The client sends the 'If-None-Match' header with the ETag value to ask the server if the resource has changed.
What does the server respond with if the ETag matches the client's version?
A304 Not Modified
B500 Internal Server Error
C404 Not Found
D200 OK with full content
✗ Incorrect
A 304 Not Modified response tells the client to use its cached version because the resource has not changed.
Which Node.js framework commonly helps manage ETags automatically?
AExpress.js
BReact
CVue.js
DAngular
✗ Incorrect
Express.js has built-in support and middleware to handle ETags and conditional requests.
What is the main benefit of using ETags in web applications?
ASpeeds up server processing by caching requests
BImproves security by encrypting data
CReduces bandwidth by avoiding sending unchanged data
DAllows multiple users to edit the same resource simultaneously
✗ Incorrect
ETags help reduce bandwidth by letting clients reuse cached data when the resource hasn't changed.
If a client sends an ETag that does not match the server's current ETag, what happens?
AServer sends 304 Not Modified
BServer closes the connection
CServer sends 403 Forbidden
DServer sends 200 OK with updated resource
✗ Incorrect
If the ETags don't match, the server sends the full updated resource with a 200 OK status.
Explain how ETags and conditional requests work together to optimize web resource loading.
Think about how your browser checks if a file has changed before downloading it again.
You got /5 concepts.
Describe how you would implement ETag support in a Node.js server using Express.
Express has built-in features to help with ETags and conditional requests.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of using an ETag in HTTP responses in Node.js?
easy
A. To set the cache expiration time
B. To encrypt the response data for security
C. To specify the content type of the response
D. To help browsers check if the content has changed and avoid re-downloading unchanged data
Solution
Step 1: Understand what ETag represents
ETag is a unique identifier for a specific version of a resource, used to detect changes.
Step 2: Identify its role in HTTP caching
Browsers use ETag to check if the resource changed since last download, avoiding unnecessary data transfer.
Final Answer:
To help browsers check if the content has changed and avoid re-downloading unchanged data -> Option D
Quick Check:
ETag purpose = avoid re-download [OK]
Hint: ETag means "same content? skip download" [OK]
Common Mistakes:
Confusing ETag with encryption
Thinking ETag sets content type
Mixing ETag with cache expiration headers
2. Which of the following is the correct way to set an ETag header in a Node.js HTTP response?
B. Header name case mismatch: 'If-None-Match' vs 'if-none-match'
C. res.end() is missing a callback function
D. res.statusCode must be set after res.end()
Solution
Step 1: Check header name case sensitivity in Node.js
Node.js lowercases all incoming header names, so req.headers['If-None-Match'] is undefined; correct is req.headers['if-none-match'].
Step 2: Confirm impact on ETag comparison
Because the header is undefined, the condition never matches, so 304 is never sent.
Final Answer:
Header name case mismatch: 'If-None-Match' vs 'if-none-match' -> Option B
Quick Check:
Headers lowercase in Node.js = use 'if-none-match' [OK]
Hint: Node.js headers are lowercase keys [OK]
Common Mistakes:
Using wrong case for header keys
Thinking ETag must be numeric
Misordering res.statusCode and res.end()
5. You want to optimize your Node.js server to use ETags and respond with 304 when content is unchanged. Which approach correctly combines generating an ETag and handling conditional requests?
hard
A. Generate a hash of the response body, set it as ETag header, then compare with req.headers['if-none-match'] to decide 304 or 200
B. Always send status 200 with ETag header, ignoring If-None-Match header
C. Set ETag header only on POST requests and ignore GET requests
D. Use res.setHeader('Cache-Control', 'no-store') to disable caching instead of ETags
Solution
Step 1: Understand ETag generation
ETags should uniquely represent the current content, often by hashing the response body.
Step 2: Use conditional request header to decide response
Compare req.headers['if-none-match'] with generated ETag; if equal, respond 304, else send content with new ETag.
Final Answer:
Generate a hash of the response body, set it as ETag header, then compare with req.headers['if-none-match'] to decide 304 or 200 -> Option A
Quick Check:
Hash body -> set ETag -> compare If-None-Match -> 304 or 200 [OK]
Hint: Hash content, set ETag, compare If-None-Match for 304 [OK]
Common Mistakes:
Ignoring If-None-Match header
Sending 200 always without checking ETag
Misusing Cache-Control to replace ETag logic
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.