gpt4 book ai didi

asp.net - 我可以使用 ASP.NET 提前刷新缓冲区吗?

转载 作者:行者123 更新时间:2023-12-03 05:16:29 25 4
gpt4 key购买 nike

Best Practices for Speeing Up Your Web Site来自雅虎的建议包括以下内容:

When users request a page, it can take anywhere from 200 to 500ms for the backend server to stitch together the HTML page. During this time, the browser is idle as it waits for the data to arrive. In PHP you have the function flush(). It allows you to send your partially ready HTML response to the browser so that the browser can start fetching components while your backend is busy with the rest of the HTML page. The benefit is mainly seen on busy backends or light frontends.

A good place to consider flushing is right after the HEAD because the HTML for the head is usually easier to produce and it allows you to include any CSS and JavaScript files for the browser to start fetching in parallel while the backend is still processing.

Example:

... <!-- css, js -->
</head>
<?php flush(); ?>
<body>
... <!-- content -->

请注意,此处发生刷新的时间点是在写入 head 标记之后。这很有意义,因此浏览器可以开始加载图像和脚本,同时渲染和提供页面的其余部分。

有没有办法使用 ASP.NET 显式地在头部(或页面的任何其他部分)之后刷新?

最佳答案

您应该能够将以下内容放在页面中的 head 末尾和 body 语句开头之间:

<% Response.Flush(); %>

但是,如果您使用脚本管理器或任何其他类型的控件,它们会在 html 的 head 部分中注册自身以进行输出,请务必小心。

关于asp.net - 我可以使用 ASP.NET 提前刷新缓冲区吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/678811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com