1

I must be doing something wrong, but I am trying to ping a service until I get a 200 response. When I look in the network tab in my browser (chrome), I get a 304:

enter image description here

However, when I print out the following code:

const s1 = await fetch(`./${cluster}/api`) const s2 = await fetch(`./${cluster}/dashboard`) console.log(s1.status, s2.status) 

I get:

enter image description here

It's hard to read sorry, but it says 200 200.

Why do I get a 200 when I check the status, but a 304 in the network tab?

1 Answer 1

4

As you can see from here (scroll down to "redirect):

Normally, fetch transparently follows HTTP-redirects, like 301, 302 etc.

fetch follows HTTP redirects, so you are getting a 304, fetch will then load the page from cache, since a 304 Not Modified means that the cached page is still valid.

Also work reading https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections#special_redirections

Sign up to request clarification or add additional context in comments.

5 Comments

Just a clarification, for a 304 Not Modified, the browser will load from cache. I don't think there's any "new URL" involved
@Phil yes you're right, I'll edit the question with the clarification, thank you
I can ask this as a different question if needed, but is there a way to get the 304 back? I tried setting to manual and error as shown in the link to no avail. Still 200.
@AdamJohnston you can probably set redirect to manual, check this developer.mozilla.org/en-US/docs/Web/API/Fetch_API/…
Still 200, oh well. I can figure out another way to do this. Thanks again.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.