An ETag (Entity Tag) is a unique identifier assigned by a server to a specific version of a resource. It helps clients know if the resource has changed since the last time they accessed it.
Click to reveal answer
beginner
How does a client use an ETag for conditional requests?
The client sends the ETag value in the 'If-None-Match' header when requesting a resource. The server compares it with the current ETag and returns the resource only if it has changed; otherwise, it returns a 304 Not Modified status.
Click to reveal answer
beginner
What HTTP status code indicates that the resource has not changed when using ETag?
The server returns HTTP status code 304 Not Modified to tell the client that the resource has not changed and the cached version can be used.
Click to reveal answer
intermediate
Why are ETags useful for web performance?
ETags reduce bandwidth and improve performance by allowing clients to avoid downloading unchanged resources. This saves time and network data by using cached versions when possible.
Click to reveal answer
intermediate
What is the difference between a strong and a weak ETag?
A strong ETag changes whenever the resource changes in any way. A weak ETag may not change for minor differences and is prefixed with 'W/'. Weak ETags allow some flexibility in caching but may not detect all changes.
Click to reveal answer
What header does a client send to use an ETag for conditional GET requests?
AIf-None-Match
BIf-Match
CETag
DCache-Control
✗ Incorrect
The client sends the ETag value in the 'If-None-Match' header to ask the server if the resource has changed.
What does the server return if the resource has not changed when using ETag?
A304 Not Modified
B404 Not Found
C200 OK with resource
D500 Internal Server Error
✗ Incorrect
The server returns 304 Not Modified to indicate the cached resource is still valid.
Which of the following best describes a weak ETag?
AAn ETag that is always a hash of the resource content
BAn ETag that changes with every minor change
CAn ETag used only for POST requests
DAn ETag prefixed with 'W/' that may not change for minor differences
✗ Incorrect
Weak ETags are prefixed with 'W/' and allow some flexibility by not changing for minor differences.
Why are ETags important for caching?
AThey force the client to always download the resource
BThey help the client know if the cached resource is still valid
CThey encrypt the resource data
DThey replace the URL of the resource
✗ Incorrect
ETags help clients check if their cached copy is still valid, avoiding unnecessary downloads.
Which HTTP method commonly uses ETags for conditional requests?
APUT
BDELETE
CGET
DOPTIONS
✗ Incorrect
ETags are most commonly used with GET requests to check if the resource has changed.
Explain how ETags help improve web application performance.
Think about how caching works with version checks.
You got /5 concepts.
Describe the difference between strong and weak ETags and when you might use each.
Consider strictness of change detection.
You got /5 concepts.
Practice
(1/5)
1.
What is the main purpose of an ETag in REST APIs?
easy
A. To help clients check if the resource has changed since last fetch
B. To encrypt the data sent from server to client
C. To authenticate the client making the request
D. To specify the content type of the response
Solution
Step 1: Understand ETag role in REST
ETags are unique identifiers for resource versions, used to detect changes.
Step 2: Match purpose with options
Only To help clients check if the resource has changed since last fetch describes checking if resource changed, which is the ETag's purpose.
Final Answer:
To help clients check if the resource has changed since last fetch -> Option A
Quick Check:
ETag purpose = freshness check [OK]
Hint: ETags track changes, not encrypt or authenticate [OK]
Common Mistakes:
Confusing ETag with authentication tokens
Thinking ETag encrypts data
Assuming ETag sets content type
2.
Which HTTP header should a client send to make a conditional GET request using an ETag?
easy
A. If-Modified-Since
B. If-None-Match
C. ETag
D. Cache-Control
Solution
Step 1: Identify client header for ETag conditional requests
The client sends If-None-Match header with the ETag value to check freshness.
Step 2: Compare options
If-Modified-Since uses dates, ETag is a response header, Cache-Control controls caching rules. Only If-None-Match fits.
Final Answer:
If-None-Match -> Option B
Quick Check:
Client uses If-None-Match for ETag check [OK]
Hint: Client sends If-None-Match with ETag to check freshness [OK]
Common Mistakes:
Using ETag header in request instead of response
Confusing If-Modified-Since with ETag usage
Sending Cache-Control instead of conditional header
3.
Given this HTTP interaction: GET /resource HTTP/1.1 Host: example.com If-None-Match: "abc123" Server responds: HTTP/1.1 304 Not Modified What does this response mean?
medium
A. The resource has changed and new data is sent
B. The server encountered an error
C. The resource has not changed; client should use cached data
D. The request is unauthorized
Solution
Step 1: Understand 304 Not Modified status
304 means resource is unchanged since client's ETag, so no new data sent.
Step 2: Match meaning with options
The resource has not changed; client should use cached data correctly states client should use cached data because resource is unchanged.
Final Answer:
The resource has not changed; client should use cached data -> Option C
A. It compares ETag strings without quotes, causing mismatch
B. It returns 304 even if ETag does not match
C. It does not handle If-Modified-Since header
D. It always returns data ignoring conditional requests
Solution
Step 1: Analyze ETag comparison
ETags in headers often include quotes, so direct string equality may fail if quotes differ.
Step 2: Identify mismatch cause
If client sends "abc123" but server etag is abc123 without quotes, comparison fails incorrectly.
Final Answer:
It compares ETag strings without quotes, causing mismatch -> Option A
Quick Check:
ETag quotes matter in comparison [OK]
Hint: ETag strings must match exactly including quotes [OK]
Common Mistakes:
Ignoring quotes around ETag values
Assuming If-Modified-Since is required for ETag logic
Returning 304 without checking ETag
5.
You want to optimize your REST API to reduce bandwidth by using ETags. Which approach correctly implements conditional GET requests with ETags?
1. Server generates ETag for resource. 2. Server sends ETag in response header. 3. Client stores ETag. 4. Client sends GET with If-None-Match header. 5. Server compares ETag and returns 304 if unchanged. 6. Otherwise, server sends new data with new ETag.
Which step is missing or incorrect?
hard
A. Step 6: Server should always send 200 status even if unchanged
B. Step 4: Client should send If-Modified-Since instead of If-None-Match
C. Step 3: Client should not store ETag
D. Step 5: Server must compare ETag including quotes exactly
Solution
Step 1: Review each step for correctness
Steps 1-4 are correct standard flow for ETag conditional requests.
Step 2: Identify subtle issue in step 5
Server must compare ETag values exactly, including quotes, or else conditional check fails.
Step 3: Confirm other options are incorrect
Client should store ETag (step 3), If-None-Match is correct header (step 4), and 304 status is correct for unchanged (step 6).
Final Answer:
Step 5: Server must compare ETag including quotes exactly -> Option D
Quick Check:
Exact ETag match including quotes is required [OK]
Hint: ETag comparison must be exact including quotes [OK]
Common Mistakes:
Ignoring quotes in ETag comparison
Using wrong conditional header
Sending 200 instead of 304 for unchanged resource
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.