为什么 HTML5 不包含将本地 HTML 加载到文档中的方法?
我最近一直在思考这个问题.为什么 HTML5不是真的让您将 HTML 加载到文档中以分解您的 HTML 文件?
I've thinking about this a lot lately. Why does HTML5 not really let you load HTML into your document to break up your HTML files?
它支持几乎所有其他资产(图像、视频、音频).
It has support for nearly every other asset (images, videos, audio).
是的,我们有 iframes
、embeds
和 objects
,但它们是沙盒的,不遵循文档其余部分的流程.
Yes we have iframes
, embeds
, and objects
but they are sandboxed and don't follow the flow of the rest of the document.
我在想这样的事情:
<h2>My wonderful application</h2>
<include src = "leftPane.html" type = "text/html" />
<include src = "main.html" type = "text/html" />
<include src = "footer.html" type = "text/html" />
我希望有人向我解释这一点.在我们制作的几乎每一个 Web 应用程序中,我们都使用某种形式的模板来分解我们的 HTML,那么为什么 HTML5 不只是包含它呢?
I would love for someone to explain this to me. In nearly every web application we make, we use some form of templating to break up our HTML, so why does HTML5 not just include it?
我很感激你的(无火焰的)想法.
I'd appreciate your (flameless) thoughts.
马特
推荐答案
事实证明,这已经出现在 WHATWG 邮件列表中:客户端包含提案:Shannon 准确地提出了您所说的内容,解析器在加载文档片段时必须阻塞.Ian Hickson 拒绝了它,因为延迟成本太高.此外,这是许多 Web 服务器已经提供的简单功能,因此被认为不值得.
As it turns out, this has come up in the WHATWG mailing lists: Client-side includes proposal: Shannon proposed exactly what you are saying, where the parser has to block while loading document fragments. Ian Hickson rejected it because the latency cost is too high. Besides, it's a simple feature that many web servers already provide, so it was deemed not worth the cost.
您可能希望使用 seamless
属性的 iframe
,它会导致将完整文档放置在文档中,但其作用类似于任何块元素(继承主文档中的样式).不过,我认为它还没有被许多浏览器支持.
You may instead want to investigate using the seamless
attribute of iframe
, which causes a full document to be placed within the document but act like any block element (inheriting styles from the host document). I don't think it's supported by many browsers yet though.
相关文章