title: Why does JavaScript's fetch() not need to check for status code 304?
body: <p>The code to show how to use <code>fetch()</code> properly, even to handle <code>404</code> or <code>500</code> which is considered not an error, is <a href="https://javascript.info/fetch" rel="nofollow noreferrer">to check for <code>response.ok</code></a>:</p>
  <pre><code>fetch(&quot;   &quot;)
    .then(response =&gt; {
      if (response.ok) return response.json();
      else throw new TypeError(&quot;No fetch data&quot;);
    })
    .then(d =&gt; setData(d))
    .catch(err =&gt; { handleError(err); });
  </code></pre>
  <p>or to check for <code>response.status</code>, but the goal is to <a href="https://developer.mozilla.org/en-US/docs/Web/API/Response/ok" rel="nofollow noreferrer">check for status code being in the range of 200 to 299, inclusive, which is what <code>response.ok</code> can do</a>.</p>
  <p>However, if the status code is <code>304</code>, which means data has not changed, why does this case not need to be handled?  I do remember in the days of jQuery, the code <code>304</code> is always checked for as well, which means it is a valid form of data.  On <a href="https://code.jquery.com/jquery-3.6.0.js" rel="nofollow noreferrer">https://code.jquery.com/jquery-3.6.0.js</a></p>
  <pre><code>isSuccess = status &gt;= 200 &amp;&amp; status &lt; 300 || status === 304;
  </code></pre>
  <p>I can only see in <a href="https://fetch.spec.whatwg.org/#http-network-or-cache-fetch" rel="nofollow noreferrer">the specs for <code>fetch()</code></a></p>
  <blockquote>
  <p>If response is null, then: ... If the revalidatingFlag is set and forwardResponse’s status is 304, then:  ... Set response to storedResponse.</p>
  </blockquote>
  <p>So it looks like the response is set to the cached version, but I don't see the mentioning of changing the <code>304</code> to <code>200</code>.</p>
  <p>Why does we not need to consider the case for <code>304</code> in the case of <code>fetch()</code>?</p>