Challenge - 5 Problems
Expires Directive 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 Expires directive in nginx?
Given the nginx configuration snippet:
What will be the Cache-Control header value sent to clients for files under /images/?
location /images/ {
expires 30d;
}What will be the Cache-Control header value sent to clients for files under /images/?
Nginx
location /images/ {
expires 30d;
}Attempts:
2 left
💡 Hint
30d means 30 days in seconds for max-age.
✗ Incorrect
The 'expires 30d;' directive sets the Cache-Control max-age to 30 days, which is 2592000 seconds.
🧠 Conceptual
intermediate1:30remaining
How does the 'expires' directive affect browser caching?
Which statement best describes the role of the 'expires' directive in nginx?
Attempts:
2 left
💡 Hint
Think about cache duration.
✗ Incorrect
The 'expires' directive tells browsers how long to keep a resource cached before fetching it again.
❓ Configuration
advanced2:00remaining
Which nginx configuration sets no caching for CSS files?
You want to configure nginx to prevent caching of CSS files. Which configuration snippet achieves this?
Attempts:
2 left
💡 Hint
'expires off;' disables caching.
✗ Incorrect
'expires off;' disables the Expires header and sets Cache-Control to no-cache, preventing caching.
❓ Troubleshoot
advanced2:00remaining
Why is the Expires header not set as expected?
You configured nginx with:
But clients do not receive the Expires header. What is a likely cause?
location /static/ {
expires 7d;
}But clients do not receive the Expires header. What is a likely cause?
Attempts:
2 left
💡 Hint
Check if the location block matches the request path.
✗ Incorrect
If the location block is not matched by the request, the expires directive inside it won't apply.
✅ Best Practice
expert2:30remaining
What is the recommended way to set long cache expiration for versioned static assets?
You have static assets with filenames including version hashes (e.g., app.abc123.js). What is the best practice for setting the 'expires' directive in nginx?
Attempts:
2 left
💡 Hint
Versioned filenames allow safe long caching.
✗ Incorrect
Using 'expires max;' allows browsers to cache versioned assets indefinitely, improving performance without stale content risk.