0
0
Node.jsframework~10 mins

HTTP caching headers in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set a Cache-Control header that allows caching for 1 hour.

Node.js
res.setHeader('Cache-Control', '[1]');
Drag options to blanks, or click blank then click option'
Aprivate, max-age=0
Bno-cache
Cpublic, max-age=3600
Dno-store
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'no-cache' or 'no-store' disables caching.
Forgetting to specify max-age causes no caching duration.
2fill in blank
medium

Complete the code to set the ETag header with a unique value.

Node.js
res.setHeader('ETag', '[1]');
Drag options to blanks, or click blank then click option'
Aetag-12345
B"12345"
Cetag123
D12345
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the ETag value causes header parsing errors.
Using non-unique ETag values defeats caching benefits.
3fill in blank
hard

Fix the error in setting the Expires header to 1 day from now.

Node.js
const expires = new Date(Date.now() + [1]).toUTCString();
res.setHeader('Expires', expires);
Drag options to blanks, or click blank then click option'
A86400000
B3600000
C60000
D1000
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3600000 sets only 1 hour instead of 1 day.
Using 60000 sets only 1 minute.
4fill in blank
hard

Fill both blanks to set Cache-Control for private caching and must-revalidate directive.

Node.js
res.setHeader('Cache-Control', '[1], [2]');
Drag options to blanks, or click blank then click option'
Aprivate
Bpublic
Cmust-revalidate
Dno-store
Attempts:
3 left
💡 Hint
Common Mistakes
Using public instead of private allows shared caching.
Omitting must-revalidate may cause stale content.
5fill in blank
hard

Fill all three blanks to set Cache-Control with max-age 600 and no-transform directives.

Node.js
res.setHeader('Cache-Control', '[1]=[2], [3]');
Drag options to blanks, or click blank then click option'
Amax-age
B600
Cno-store
Dno-transform
Attempts:
3 left
💡 Hint
Common Mistakes
Using no-store with max-age is contradictory but allowed; no-store disables caching.
Forgetting to provide max-age value causes errors.