JavaScript Answers

How to send no cache headers in Node.js server?

Spread the love

To send no cache headers in Node.js server, we call the writeHead method.

For instance, we write

res.writeHead(200, {
  "Content-Type": mimeType,
  "Content-Length": contents.length,
  "Accept-Ranges": "bytes",
  "Cache-Control": "no-cache",

to call writHeader with an object with the response headers and values.

We return the Content-Type, Content-Length, Accept-Ranges, and Cache-Control headers.

We set Cache-Control to no-cache to disable cache.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.