跳到主要内容

4.15. 使用 Server Push

4.15. 使用 Server Push (Using Server Push)

HTTP/2 [HTTP/2] 引入 server push, 允许 server 在不等待 request 的情况下向 client 发送 response. 这可以允许 server 主动发送 client 可能需要的 resource, 从而改善性能.

然而, 实践证明 server push 难以有效使用. 它需要仔细考虑:

  • push 哪些 resource.

  • 何时 push.

  • 如何避免 push client 已拥有的 resource.

  • 如何与 caching 协调.

因此, server push 并未被广泛使用, 且某些 browser 已移除对它的支持. HTTP/3 [HTTP/3] 不包含 server push.

希望使用 server push 的 application SHOULD:

  • 仔细评估 push 是否确实会改善其 use case 的性能.

  • 考虑替代方案, 例如 inline resource 或使用 early hints [RFC8297].

  • 为不支持或不接受 pushed resource 的 client 做好准备.

  • 清楚规定何时 push 以及 push 哪些 resource.

鉴于 server push 的采用和支持有限, application SHOULD NOT 要求它作为正确运行的必要条件.