简体   繁体   中英

iOS Safari random slow image loading with iisnode

I have a website on node.js. I host the application with iisnode.

I have a page that displays a large amount photos in a style like Pinterest. The images are loaded as plain <img /> with proper src being appended to DOM. The images are plain static resource on the server.

All images load almost instant on latest windows Chrome, Android Chrome, and even iOS Chrome.

However, on iOS Safari, for each hundred of photos, randomly, one or two photos will not be loaded instantly, instead, those photos will be loaded in about 20-30 seconds. The Safari developer debugger says there is a 20-30 second latency for that image request.

The problem doesn't exist if I don't use IISNode and use node.exe as the web server directly. I suspect there is some weird compatibility issue between IISnode and iOS Safari. It seems to me, IISNode triggers something in iOS Safari that blocks HTTP connectivity.

What is the cause of this issue?

The situation is related to HTTP header Connection:keep-alive .

IIS is designed not to include response header Connection:keep-alive , so IISNode is no exception here. This behavior is presumably ok for desktop browsers and Android browsers. However without Connection:keep-alive it seems iOS Safari will run into a situation I would call TCP deprivation where old connections are not reused and new connection cannot be created because old connections are still open and the limit of total number of open connection has been reached. I personally think this theory explains that 20-30 seconds latency behavior. At the end of that 20-30 seconds, old connections are finally closed and new connection can be made.

The combination of iOS Safari and IISNode caused the problem. Since it is not possible to make IIS include Connection:keep-alive . Serving everything inside Node.exe directly without the IISNode proxy layer is the solution to this problem.

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