Prevent cache when serving a JSON response in Node.js api
<p>I have a mobile app that will periodically pull a JSON file from a Node.js server. </p>

<p>THE JSON response is dynamically generated with random values. It should not be cached at all.</p>

<p>I tried to prevent caching:</p>

<pre><code>app.get('/important.json', function(req, res) {
        res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
        res.setHeader("Pragma", "no-cache");
        res.setHeader("Expires", 0);
        res.json(...);
});
</code></pre>

<p>However, when the mobile app reloads the json, it is still getting 304 Not Modified response from the server (Observed from Fiddler). </p>

<p><a href="https://i.stack.imgur.com/7xrz0.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7xrz0.jpg" alt="enter image description here"></a></p>

<p>Can someone advise if the anti-cache is done correctly? Is it due to the etag? If etag is the problem, can I disable etag specifically for this api/endpoint?</p>