简体   繁体   中英

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:

80端口请求:

Requesto to port 4567:

非 80 端口请求

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

Any idea?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM