ESPAsyncWebServer returns 200 but browser fails to retrieve resource

I'm using the well-known ESPAsyncWebServer library.
For common resources I use a static serve:

  _server.serveStatic("/", LittleFS, "/www")
      .setDefaultFile("index.html")
      .setTemplateProcessor(std::bind(&WebApp::processor, this, std::placeholders::_1));

it happens that sometimes the browser fails to retrieve a file (i.e. a CSS). Using the developer tools I see "(failed)" in the network tab. But clicking on the file, the details on the right inside the headers tab shows: "200 OK".

I wonder how is it possible the server's response is 200 if the browser failed to retrieve the resource.
Usually hitting shift+F5 leads to the correct behavior, but sometimes I have to restart the ESP32 otherwise the file is not loaded.

the HTTP status code 200 OK is specific to the request for index.html and indicates that the server successfully delivered that specific resource. The success or failure of other resource requests is handled separately by the browser.

➜ In more details, when you request http://www.site.com/index.html, the HTTP server processes the request for index.html and your esp32 receives the query, gets the file and returns it.
If index.html is found and there are no server-side issues, the server returns an HTTP status code 200 OK along with the contents of the HTML file.

Then if index.html contains references to other resources (like CSS, JavaScript, images, etc.), the browser will make additional HTTP requests to retrieve those resources and If any of these additional resources cannot be retrieved (due to reasons like the resource not being found, a network error, or server issues), those specific requests will return an error code (like 404 Not Found or 500 Internal Server Error), but this does not affect the original 200 OK status for index.html.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.