Stefano Martini
Stefano Martini

Reputation: 455

ESP32 Asynch Web Server is slow in port 80 serveStatic from SPIFFS get slow web server

I'm having a problem with my esp32 using async we server.

I have two server running with async web server library and I don't know why, port 80 is very slow, take a look:

The answer is the same code for each server, only port change.

Request to port 80:

Request in port 80:

Requesto to port 4567:

Request in non 80 port

Wy port 80 is 10 time slower??? I was thinking about Chrome but olso postman and firefox figure the same problem.

Any idea?

Upvotes: 1

Views: 2498

Answers (1)

Stefano Martini
Stefano Martini

Reputation: 455

After some tryes I found the problem.

No the fault is not about port 80, browser or any other faboulus things between esp32 and the user.

  server.serveStatic("/assets/", SPIFFS, "/assets/").setCacheControl("max-age=31536000");

I used this function for serve pages with cahce, not exactly, the function whas this:

  server.serveStatic("/", SPIFFS, "/").setCacheControl("max-age=31536000");

I don't know exactly why, but what was after this was drasticaly slow.

After moving all my "api" endpoint before, response are faster then the other server in the other ports.

Furthermore using:

server.serveStatic("/", SPIFFS, "/").setCacheControl("max-age=31536000");

don't set automatically the cache header of the web pages stored in the "/" folder, cause there's a server.on listenging for that url, the cache header is applyed only if you are going to get the file.

Ex:

http:/espipaddres/page.html -> will have cache header

http:/espipaddres/page

with a

  server.on("/page", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(SPIFFS, "/page.html", "text/html");
  });

will not have cache header

Upvotes: 2

Related Questions