简体   繁体   English

ESP32 异步 Web 服务器在端口 80 上很慢 来自 SPIFFS 的 serverStatic 变慢 web 服务器

[英]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.我的 esp32 使用 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:我有两台服务器运行异步 web 服务器库,我不知道为什么,端口 80 很慢,看看:

The answer is the same code for each server, only port change.答案是每台服务器的代码相同,只是端口更改。

Request to port 80:请求端口 80:

80端口请求:

Requesto to port 4567:向端口 4567 请求:

非 80 端口请求

Wy port 80 is 10 time slower???为什么端口 80 慢了 10 倍??? I was thinking about Chrome but olso postman and firefox figure the same problem.我在考虑 Chrome,但 olso postman 和 firefox 也出现了同样的问题。

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.不,错误不在于端口 80、浏览器或 esp32 与用户之间的任何其他 faboulus 事物。

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

I used this function for serve pages with cahce, not exactly, the function whas this:我使用这个 function 来提供带有cahce的页面,不完全是,function 是这样的:

  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.在移动我之前的所有“api”端点之后,响应速度比其他端口中的其他服务器更快。

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. 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.html ->将有缓存 header

http:/espipaddres/page http:/espipaddres/page

with a

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

will not have cache header不会有缓存 header

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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