I want to implement a node script which should download some images from remote sites, say once every hour, with a local cache, on filesystem.
I would like to know if it's possible to add something like an "if-modified-since" tag in the node fetch request headers, to let the remote server to return a 304 status, instead of a 200 with the full image body, if the image is not changed.
The code I use is something like:
const response = await fetch(imageUrl, {
headers: {'If-Modified-Since': new Date().toUTCString()}
});
I.e.: I use the current date, but no 304 from the remote server...
UPDATE:
I did finally realise my mistake: I was removing the double quotes from the etag... The starting and trailing quotes in etag must be included in If-None-Match
value... With double quotes, server correctly returns 304 if image is not changed.
Thanks to @bergui for your help...