使用 Transfer-Encoding: chunked on static files 是个好主意吗? [英] Is it a good idea to use Transfer-Encoding: chunked on static files?

查看:35
本文介绍了使用 Transfer-Encoding: chunked on static files 是个好主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有你常用的静态站点,服务器在其中抓取 .html 文件并发送它们.

I've got your usual static site, where the server grabs .html files and sends them.

我理解 Transfer-Encoding: chunked 对于动态服务器页面的重要性,因为这就是它的设计目的.加速可能非常令人难以置信.但是静态文件的速度提升是否相同?浏览器是否已经逐步呈现&使用 Content-Length 的请求获取,因为文件通过网络到达?

I understand the importance of Transfer-Encoding: chunked for dynamic server pages, since that's what it was designed for. The speedup can be pretty incredible. But is it the same speed increase for static files? Do browsers already progressively render & fetch with requests that use Content-Length, as the file arrives over the wire?

我有一些非常庞大的 HTML(百页范围内的文档),因此渐进式 HTML 处理至关重要.(有点像 WHATWG 如何提供单一的单页 HTML5 规范.)

I've got some seriously enormous HTML (documents in the hundred-page range), so progressive HTML processing would be crucial. (Kind of like how the WHATWG delivers the monolithic single-page HTML5 spec.)

推荐答案

简短回答:是的,浏览器确实会逐步呈现使用 Content-Length 标头发送的内容.事实上,如果浏览器有 Content-Length 标头,它的计算会少一些,因为它预先知道文档有多长,而不必解析文档以获得块信息.

Short answer: Yes, browsers do progressively render content sent with the Content-Length header. In fact, the browser does a bit less computing if it has the Content-Length header, since it knows up front how long the document is versus having to parse the document for the chunk information.

Content-Length 标头(如果有)必须在发送任何内容之前发送.因此,服务器在发送任何文档内容之前必须知道文档的长度.

The Content-Length header (if any) must be sent before any of the content is sent. Therefore, the server must know the length of the document before sending any of the document content.

分块编码更快仅适用于动态内容.如果服务器只能使用 Content-Length 标头,对于动态内容,它需要在发送任何内容之前完成文档生成.这可能会导致客户端等待,可能很长时间没有看到任何文档.

Chunked encoding is faster for dynamic content only. If a server could only use the Content-Length header, for dynamic content it would need to finish the document generation before sending out any content at all. This can cause the client to wait, possibly a long time without seeing any of the document.

分块编码通过允许服务器不必发送 Content-Length 标头来解决这个问题.

Chunked encoding solves this by allowing the server to not have to send the Content-Length header.

这篇关于使用 Transfer-Encoding: chunked on static files 是个好主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆