1

I've noticed that when I refresh my app one of my JS assets is sometimes loaded with 304 response, while mostly it is loaded with 200 (from cache). It wouldn't be a big deal, if it would actually load it - whenever I get 304, the file is not loaded (the response is empty) and I end up with JS error (because my var from that file is not recognized). After the error, I copy-paste the URL to a new tab and then my JS file is loaded correctly.

But when I refresh the page instead, I have the same error, strangely not always - after several refresh attempts the file is loaded with 200 and JS error is gone.

I wish I would know what could cause this strange behavior, or how can I force to load this file.

van_folmert
  • 4,257
  • 10
  • 44
  • 89
  • 304 is the server telling the client (your browser) that the version it already has cached is up to date and that there is no need to save a new one. A 304 response has no content because the browser already has it. As for why it's failing, my guess is there's something else at play here. Is the script block marked as async? – Richard Szalay Feb 10 '16 at 11:06
  • "the browser already has it" - you mean in the cache? So then it should make a second request for it with 200 response (from cache)? Because in my case it does not. No, there is no async attribute in the script. – van_folmert Feb 10 '16 at 12:11
  • (The browser will not make another request if the server returns 304 - that is normal) What headers are returned with the 304? Have you tried updating the server to remove the max-age/expires header? Doing so would skip the 304 request/response. – Richard Szalay Feb 10 '16 at 19:57
  • Response headers: **Connection:** Keep-Alive, **Date:** Thu, 11 Feb 2016 09:05:52 GMT, **ETag:** "7bad-52b7ab7e48997", **Keep-Alive:** timeout=5, max=88, **Server:** Apache/2.4.16 (Win32) OpenSSL/1.0.1p PHP/5.6.12. Updating the server - you mean the Apache? – van_folmert Feb 11 '16 at 09:07
  • If the server is internet accessible, can you create a codepen that reproduces the issue? – Richard Szalay Feb 11 '16 at 10:57
  • Sorry, not possible, it's in the VPN and way too big for a codepen anyway. – van_folmert Feb 12 '16 at 08:07

0 Answers0