Challenge - 5 Problems
Cache-Control Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the effect of this Cache-Control header in nginx?
Given this nginx configuration snippet, what Cache-Control header will be sent to clients?
location /images/ {
add_header Cache-Control "public, max-age=86400";
}Nginx
curl -I http://example.com/images/logo.png
Attempts:
2 left
💡 Hint
Look at the add_header directive and the value it sets.
✗ Incorrect
The add_header directive sets the Cache-Control header exactly as specified. Here it sets it to 'public, max-age=86400', meaning the response can be cached by any cache for 86400 seconds (1 day).
🧠 Conceptual
intermediate2:00remaining
Which Cache-Control directive prevents caching by browsers but allows caching by proxies?
Select the Cache-Control directive that stops browsers from caching but still allows intermediate proxies to cache the response.
Attempts:
2 left
💡 Hint
Think about which directive requires revalidation but does not forbid caching.
✗ Incorrect
The 'no-cache' directive means caches must revalidate with the server before using the cached copy. Browsers will revalidate, effectively preventing stale content, but proxies can still cache it. 'private' restricts caching to browsers only, 'no-store' forbids caching entirely, and 'public' allows caching everywhere.
❓ Configuration
advanced2:00remaining
How to configure nginx to disable caching for all HTML files?
Choose the correct nginx configuration snippet that disables caching for all .html files by setting Cache-Control headers.
Attempts:
2 left
💡 Hint
Disabling caching means telling browsers and proxies not to store the response.
✗ Incorrect
The configuration in option B sets Cache-Control headers that instruct browsers and proxies not to cache the HTML files by using 'no-store' and 'no-cache' along with revalidation directives and max-age=0. Other options allow caching.
❓ Troubleshoot
advanced2:00remaining
Why is nginx not sending Cache-Control headers despite add_header directive?
You added 'add_header Cache-Control "max-age=3600";' inside a location block, but curl responses do not show Cache-Control headers. What is the most likely reason?
Attempts:
2 left
💡 Hint
Check nginx behavior for error responses and add_header.
✗ Incorrect
By default, nginx only adds headers with add_header on successful (2xx) responses. For error responses (4xx, 5xx), add_header is ignored unless you use 'always' parameter. So if the response is an error, Cache-Control won't be sent.
🔀 Workflow
expert2:00remaining
Order the steps to implement and verify Cache-Control headers in nginx
Put these steps in the correct order to add Cache-Control headers and verify they work.
Attempts:
2 left
💡 Hint
Think about editing config, applying it, then testing.
✗ Incorrect
First edit the config, then reload nginx to apply changes, then test with curl, and finally confirm the header is correct.