In a Node.js HTTP server, if the response header Cache-Control is set to no-store, what will the browser do?
res.setHeader('Cache-Control', 'no-store'); res.end('Hello');
Think about what no-store means for caching.
no-store tells the browser not to save any part of the response. It must always get a fresh copy.
Choose the Node.js code snippet that correctly sets the Cache-Control header to cache the response for 3600 seconds (1 hour).
Look for the exact syntax of the max-age directive.
The correct directive is max-age with a hyphen, no spaces.
Consider this Node.js code snippet:
res.setHeader('Cache-Control', 'max-age=3600');
res.setHeader('Pragma', 'no-cache');
res.end('Hello');Why will the browser not cache this response?
res.setHeader('Cache-Control', 'max-age=3600'); res.setHeader('Pragma', 'no-cache'); res.end('Hello');
Remember legacy headers can override modern ones.
The 'Pragma: no-cache' header is a legacy HTTP 1.0 header that tells browsers not to cache. It overrides 'Cache-Control' directives.
Given this Node.js code snippet:
const crypto = require('crypto');
const body = 'Hello World';
const etag = crypto.createHash('md5').update(body).digest('hex');
res.setHeader('ETag', etag);
res.end(body);What is the value of the ETag header?
const crypto = require('crypto'); const body = 'Hello World'; const etag = crypto.createHash('md5').update(body).digest('hex'); res.setHeader('ETag', etag); res.end(body);
MD5 hash of 'Hello World' is a known fixed value.
The MD5 hash of 'Hello World' is 'b10a8db164e0754105b7a99be72e3fe5'. This is set as the ETag value.
To enable client-side caching where the browser stores the response but checks with the server if it is still valid before using it, which combination of headers should a Node.js server send?
Think about caching duration and validation tokens.
Setting a positive max-age allows caching. Adding an ETag lets the browser validate if the cached copy is still fresh by asking the server.