关闭 Web 服务器连接、浏览器行为

发布于 2025-01-17 10:06:20 字数 154 浏览 3 评论 0原文

我有一个网站,只有一个页面,带有引导程序、一些 JavaScript、文本和图像。

我正在考虑制作自己的网络服务器,将所有内容发送到客户端,然后关闭连接以节省资源。

我想知道浏览器会如何表现。即使连接关闭,所有内容都已转移,是否仍能正常运行?

谢谢你!

I have a website with just a single page with bootstrap, some javascript, text and images.

I was thinking of making my own webserver that would send everything over to the client then close the connection to save resources.

I'm wondering how would browsers behave. Would everything remain functional even with a closed connection, given it's all already been transferred?

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

方圜几里 2025-01-24 10:06:20

这不是一个有帮助的优化。现有的 Web 服务器通常会在不使用客户端的几秒钟内关闭与客户端的连接。立即关闭连接不太可能产生太大影响。拥有一些打开但未使用的连接不会占用大量服务器资源或阻止其他连接工作。

从头开始构建自己的网络服务器并不容易。您自己的服务器的性能将不如 Nginx 或 Apache 等现有服务器。与使用现有服务器相​​比,您可能会产生更多的安全漏洞。您的网站可用的功能将会减少。仅仅为您的简单站点提供服务的 Web 服务器可能需要:

  • 支持 HTTP/1.0、HTTP/1.1 和 HTTP/2.0
  • 支持带有 TLS 加密协商的 HTTPS
  • 支持用于压缩的传输编码(如 gzip)
  • 您的内存缓存网站文件的性能

随着您的网站的发展,您可能可以利用 Web 服务器的更高级功能。

此外,运行您自己的网络服务器无法将您的网站托管在共享托管上,而这对于小型新网站来说是最具成本效益的选择。

如果您确实想在知道连接完成后关闭连接,那么最好配置现有服务器来执行此操作。这个问题的答案有几种告诉 Apache 关闭连接的方法: Apache:摆脱标头列表中的 Keep-Alive 条目

最终,您可能希望向您的站点添加内容分发网络 (CDN),以将您的内容推送到靠近用户的边缘节点地球。由于 CDN 充当反向代理服务器,因此用户甚至不再直接访问您的 Web 服务器,也无法获得您的密切优化。

This isn't an optimization that would be helpful. Existing web servers typically close connections to clients within a few seconds of them not being used. Closing connections immediately is unlikely to make much difference. Having a few open but unused connections doesn't take many server resources or prevent other connections from working.

Building your own web server from scratch isn't easy. Your own server isn't going to perform as well as existing servers like Nginx or Apache. You are likely to create more security vulnerabilities than using an existing server. Your website is going to have fewer features available to it. A web server just to serve your simple site would probably need to have:

  • Support for HTTP/1.0, HTTP/1.1, and HTTP/2.0
  • Support for HTTPS with TLS encryption negotiation
  • Support for transfer encoding (like gzip) for compression
  • Memory caching of your website's files for performance

As your site grows, there are likely to be even more advanced features of web servers of which you would be able to take advantage.

Furthermore, running your own web server precludes hosting your site on shared hosting, which is the most cost efficient option for small new sites.

If you really want to close connections when you know they are complete, you are better off configuring existing servers to do that. This question's answers have several ways of telling Apache to close connections: Apache: Get rid of Keep-Alive entry in the headers list

Eventually you may want to add a content delivery network (CDN) to your site to push your content out to edge nodes close to your users around the globe. Since a CDN works as a reverse proxy server, users would no longer even be hitting your web server directly and wouldn't get your close optimization.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文