HTTP caching headers tell browsers and servers how to store and reuse web resources to make loading faster and reduce network traffic.
Click to reveal answer
intermediate
Explain the difference between Cache-Control: no-cache and Cache-Control: no-store.
no-cache means the browser must check with the server before using cached data. no-store means the browser should never save the response at all.
Click to reveal answer
intermediate
What does the ETag header do in HTTP caching?
The ETag is a unique identifier for a resource version. Browsers send it back to the server to check if the resource changed, so they can avoid downloading it again if unchanged.
Click to reveal answer
beginner
How does the Expires header work?
The Expires header tells the browser a specific date and time after which the cached resource is considered stale and must be fetched again.
Click to reveal answer
intermediate
What is the role of Last-Modified header in caching?
The Last-Modified header shows when the resource was last changed. Browsers use it to ask the server if the resource has changed since that date to decide if they need to download it again.
Click to reveal answer
Which HTTP header tells the browser to always check with the server before using cached content?
AETag
BCache-Control: no-cache
CExpires
DCache-Control: no-store
✗ Incorrect
Cache-Control: no-cache means the browser must revalidate with the server before using cached content.
What does the ETag header help with?
AIdentifying resource versions for validation
BSetting cache expiration date
CPreventing caching entirely
DSpecifying content type
✗ Incorrect
ETag is a unique tag to identify resource versions and help browsers check if content changed.
If you want to prevent any caching of a response, which header should you use?
AExpires: 0
BCache-Control: no-cache
CCache-Control: no-store
DLast-Modified
✗ Incorrect
Cache-Control: no-store tells browsers not to save the response at all.
Which header specifies a date/time after which cached content is stale?
ALast-Modified
BCache-Control
CETag
DExpires
✗ Incorrect
Expires sets a specific expiration date/time for cached content.
How does the Last-Modified header help caching?
AIt tells the browser when the resource was last changed
BIt disables caching
CIt sets the cache duration
DIt identifies the resource version
✗ Incorrect
Last-Modified shows when the resource last changed, helping browsers decide if they need to reload it.
Describe how HTTP caching headers improve website performance and reduce server load.
Think about how your browser can save time by not downloading the same files again.
You got /4 concepts.
Explain the difference between Cache-Control: no-cache and Cache-Control: no-store headers.
One lets you keep data but checks before use; the other never saves it.
You got /3 concepts.
Practice
(1/5)
1. What does the Cache-Control: max-age=3600 header instruct the browser to do?
easy
A. Cache the response for 3600 seconds before checking for updates
B. Never cache the response
C. Cache the response indefinitely
D. Only cache the response if the user is offline
Solution
Step 1: Understand the max-age directive meaning
The max-age directive tells the browser how many seconds it can keep the cached response before it must revalidate.
Step 2: Interpret max-age=3600
max-age=3600 means the browser should cache the response for 3600 seconds (1 hour) before checking for a new version.
Final Answer:
Cache the response for 3600 seconds before checking for updates -> Option A
Quick Check:
max-age=3600 = Cache 1 hour [OK]
Hint: max-age sets cache time in seconds [OK]
Common Mistakes:
Confusing max-age with no-cache
Thinking max-age means no caching
Assuming max-age caches forever
2. Which of the following is the correct way to set a no-store cache control header in a Node.js HTTP response?
B. Cache the response for 0 seconds and never revalidate
C. Cache the response indefinitely without revalidation
D. Cache the response for 0 seconds and revalidate before each use
Solution
Step 1: Understand the meaning of no-cache and max-age=0
The no-cache directive means the browser must revalidate with the server before using the cached response. max-age=0 means the cached response is immediately stale.
Step 2: Combine the effects
With no-cache and max-age=0, the browser caches the response but must check with the server before each use, effectively caching for 0 seconds without skipping validation.
Final Answer:
Cache the response for 0 seconds and revalidate before each use -> Option D
Quick Check:
no-cache + max-age=0 = revalidate every time [OK]
Hint: no-cache means revalidate before use [OK]
Common Mistakes:
Thinking no-cache means no caching at all
Ignoring max-age=0 effect
Assuming browser ignores these headers
4. You wrote this Node.js code to prevent caching:
But the browser still caches the response. What is the likely mistake?
medium
A. The 'no-store' directive is misspelled
B. The response status code is missing
C. Headers are set after sending the response body
D. The Cache-Control header should be lowercase
Solution
Step 1: Check header setting timing
Headers must be set before sending the response body. If headers are set after calling res.end(), they won't be sent.
Step 2: Confirm header spelling and case
Cache-Control is case-insensitive and 'no-store' is spelled correctly, so these are not issues.
Step 3: Status code is optional for caching headers
Missing status code does not cause caching issues here.
Final Answer:
Headers are set after sending the response body -> Option C
Quick Check:
Set headers before res.end() [OK]
Hint: Set headers before sending response body [OK]
Common Mistakes:
Setting headers after res.end()
Misspelling cache directives
Assuming header case matters
5. You want to serve a JSON API response that should never be cached by browsers or proxies. Which combination of HTTP caching headers in Node.js ensures this behavior?
hard
A. res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate')
B. res.setHeader('Cache-Control', 'max-age=3600')
C. res.setHeader('Cache-Control', 'public, max-age=86400')
D. res.setHeader('Cache-Control', 'private, max-age=0')
Solution
Step 1: Understand no-store and no-cache directives
no-store prevents any caching anywhere. no-cache forces revalidation. must-revalidate requires caches to obey freshness rules strictly.
Step 2: Analyze each option
res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate') combines all directives to prevent caching fully. res.setHeader('Cache-Control', 'max-age=3600') and C allow caching. res.setHeader('Cache-Control', 'private, max-age=0') allows private caching but with max-age=0, which still permits revalidation.
Final Answer:
res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate') -> Option A
Quick Check:
no-store + no-cache = no caching [OK]
Hint: Use no-store to fully prevent caching [OK]
Common Mistakes:
Using max-age allowing caching
Confusing private with no-store
Omitting must-revalidate for strictness
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.