简体   繁体   English

使用iisnode的iOS Safari随机缓慢图像加载

[英]iOS Safari random slow image loading with iisnode

I have a website on node.js. 我在node.js上有一个网站。 I host the application with iisnode. 我使用iisnode托管应用程序。

I have a page that displays a large amount photos in a style like Pinterest. 我有一个页面以Pinterest之类的样式显示大量照片。 The images are loaded as plain <img /> with proper src being appended to DOM. 图像以纯<img />形式加载,并在DOM后面附加了适当的src。 The images are plain static resource on the server. 映像是服务器上的纯静态资源。

All images load almost instant on latest windows Chrome, Android Chrome, and even iOS Chrome. 所有图像几乎都立即加载到最新的Windows Chrome,Android Chrome甚至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. 但是,在iOS Safari上,对于每100张照片,随机不会立即加载一到两张照片,而是将在大约20-30秒内加载这些照片。 The Safari developer debugger says there is a 20-30 second latency for that image request. Safari开发人员调试器说,该图像请求有20-30秒的延迟。

The problem doesn't exist if I don't use IISNode and use node.exe as the web server directly. 如果我不使用IISNode并直接使用node.exe作为Web服务器,则不存在该问题。 I suspect there is some weird compatibility issue between IISnode and iOS Safari. 我怀疑IISnode和iOS Safari之间存在一些奇怪的兼容性问题。 It seems to me, IISNode triggers something in iOS Safari that blocks HTTP connectivity. 在我看来,IISNode触发了iOS Safari中阻止HTTP连接的某些操作。

What is the cause of this issue? 此问题的原因是什么?

The situation is related to HTTP header Connection:keep-alive . 这种情况与HTTP标头Connection:keep-alive有关

IIS is designed not to include response header Connection:keep-alive , so IISNode is no exception here. IIS设计为不包括响应头Connection:keep-alive ,因此IISNode也不例外。 This behavior is presumably ok for desktop browsers and Android browsers. 对于台式机浏览器和Android浏览器,此行为大概是可以的。 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. 但是如果没有Connection:keep-alive ,似乎iOS Safari会遇到TCP剥夺的情况,其中旧的连接不会被重用并且新的连接无法创建,因为旧的连接仍然处于打开状态,并且打开的连接总数已达到限制到达。 I personally think this theory explains that 20-30 seconds latency behavior. 我个人认为该理论可以解释20-30秒的延迟行为。 At the end of that 20-30 seconds, old connections are finally closed and new connection can be made. 在这20到30秒结束时,旧的连接最终将关闭,并且可以建立新的连接。

The combination of iOS Safari and IISNode caused the problem. iOS Safari和IISNode的组合导致了此问题。 Since it is not possible to make IIS include Connection:keep-alive . 由于不可能使IIS包含Connection:keep-alive Serving everything inside Node.exe directly without the IISNode proxy layer is the solution to this problem. 直接在没有IISNode代理层的情况下在Node.exe内部提供所有服务是解决此问题的方法。

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

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