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

标签 asp.net optimization

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/

相关文章:

algorithm - 在数组中找到最小整数,它是所有先前整数的约数

可以在用户空间代码中使用 likely/unlikely 宏吗?

c# - 如何使用 ASP.NET 反序列化 JavaScript 数组

mysql - 如何对真正的数据库密集型 Rails 操作进行基准测试和优化?

asp.net - 在数据库中存储特殊字符

c# - 匿名类型 "Nullable object must have a value"错误

python - 优化matplotlib pyplot : plotting for many small plots

python - 使用生成器作为 sorted() 的输入而不是列表理解是否值得

ASP.NET MVC : Adding selected CSS class to ActionLink if url matches current url

asp.net - 我需要将 .compiled 文件复制到生产服务器吗?