为什么我的web浏览器有时无法显示剩余的下载时间?

有时,浏览器(或其他应用程序)上忠实的下载进度表只是举手之劳,放弃显示剩余的下载时间。为什么它有时会锁定预计的下载时间,有时却无法同时报告?...

为什么我的web浏览器有时无法显示剩余的下载时间?

有时,浏览器(或其他应用程序)上忠实的下载进度表只是举手之劳,放弃显示剩余的下载时间。为什么它有时会锁定预计的下载时间,有时却无法同时报告?

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。

问题

超级用户读者Coldblackice想知道为什么他的浏览器不总是会有污点:

Occasionally, when downloading a file in a web browser, the download progress doesn’t “know” the total size of the file, or how far along in the download it is — it just shows the speed at which it’s downloading, with a total as “Unknown”.

Why wouldn’t the browser know the final size of some files? Where does it get this information in the first place?

到底在哪里?

答案

超级用户贡献者Gronostaj提供了以下见解:

To request documents from web servers, browsers use the HTTP protocol. You may know that name from your address bar (it may be hidden now, but when you click the address bar, copy the URL and paste it in some text editor, you’ll see http:// at the beginning). It’s a simple text-based protocol and it works like this:

First, your browser connects to the website’s server and sends a URL of the document it wants to download (web pages are documents, too) and some details about the browser itself (User-Agent etc). For example, to load the main page on the SuperUser site, http://superuser.com/, my browser sends a request that looks like this:

GET / HTTP/1.1 Host: superuser.com Connection: keep-alive Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) Accept-Encoding: gzip,deflate,sdch Accept-Language: pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4 Cookie: [removed for security] DNT: 1 If-Modified-Since: Tue, 09 Jul 2013 07:14:17 GMT

The first line specifies which document the server should return. The other lines are called headers; they look like this:

Header name: Header value

These lines send additional information that helps the server decide what to do.

If all is well, the server will respond by sending the requested document. The resp***e starts off with a status message, followed by some headers (with details about the document) and finally, if all is well, the document’s content. This is what the SuperUser server’s reply for my request looks like:

HTTP/1.1 200 OK Cache-Control: public, max-age=60 Content-Type: text/html; charset=utf-8 Expires: Tue, 09 Jul 2013 07:27:20 GMT Last-Modified: Tue, 09 Jul 2013 07:26:20 GMT Vary: * X-Frame-Opti***: SAMEORIGIN Date: Tue, 09 Jul 2013 07:26:19 GMT Content-Length: 139672 <!DOCTYPE html> <html> [...snip...] </html>

After the last line, SuperUser’s server closes the connection.

The first line (HTTP/1.1 200 OK) contains the resp***e code, in this case it’s 200 OK. It means that the server will return a document, as requested. When the server doesn’t manage to do so, the code will be something else: you have probably seen 404 Not Found, and 403 Forbidden is quite common, too. Then the headers follow.

When the browser finds an empty line in the resp***e, it knows that everything past that line is the content of the document it requested. So in this case <!DOCTYPE html> is the first line of the SuperUser’s homepage code. If I was requesting a document to download, it would probably be some gibberish characters, because most document formats are unreadable without prior processing.

Back to headers. The most interesting one for us is the last one, Content-Length. It informs the browser how many bytes of data it should expect after the empty line, so basically it’s the document size expressed in bytes. This header isn’t mandatory and may be omitted by the server. Sometimes the document size can’t be predicted (for example when the document is generated on the fly), sometimes lazy programmers don’t include it (quite common on driver download sites), sometimes websites are created by newbies who don’t know of such a header.

Anyway, whatever the reason is, the header can be missing. In that case the browser doesn’t know how much data the server is going to send, and thus displays the document size as unknown, waiting for the server to close the connection. And that’s the reason for unknown document sizes.


有什么要补充的解释吗?在评论中发出声音。想从其他精通技术的Stack Exchange用户那里了解更多答案吗?在这里查看完整的讨论主题。

  • 发表于 2021-04-11 17:03
  • 阅读 ( 172 )
  • 分类:互联网

你可能感兴趣的文章

这10个默认的gnome应用程序值得你花时间吗?

... Web是少数专门为Linux而设计的Web浏览器之一。在我看来,这也是最好的。我更喜欢网络而不是跨平台选项,比如GoogleChrome和Mozilla Firefox。 ...

  • 发布于 2021-03-11 15:05
  • 阅读 ( 272 )

macbook pro上的触摸栏有多有用?

...条代替键盘快捷键或鼠标指针的学习曲线太高了。这就是为什么,除非苹果以某种方式彻底改变触摸屏的操作方式,否则大多数用户都会忘记它。还有很多方法可以通过iPhone应用程序来提高Mac的生产力。 ...

  • 发布于 2021-03-13 06:15
  • 阅读 ( 267 )

5款独特的应用程序,改变你的待办事项列表,克服拖延症

... 2我的进度(web):浏览器选项卡中的简单待办事项应用程序[不再可用] ...

  • 发布于 2021-03-25 04:56
  • 阅读 ( 206 )

程序员和开发者的15个最佳chrome扩展

...是一个耻辱,因为IE远远没有符合现代网络标准。这就是为什么你需要ietab,它在一个新的标签中模拟IE,允许你测试不同版本的网站:IE6,IE7,IE8,IE9,还有ActiveX控件。如果你需要你的网站与所有浏览器兼容,无论多旧,都非...

  • 发布于 2021-03-25 18:14
  • 阅读 ( 252 )

更改web主机?cdn缓存可能会破坏您的站点

...是一个额外的失败点。当事情破裂时,不总是很容易理解为什么。但是如果您记得更新它,CDN确实可以极大地提高站点性能。 ...

  • 发布于 2021-03-26 11:23
  • 阅读 ( 198 )

如何硬刷新web浏览器(绕过缓存)

...息。要解决这个问题,很容易使用简单的键盘快捷键强制浏览器完全重新加载页面的本地副本(缓存)。下面是如何做到这一点。 什么是浏览器缓存(a browser cache)? 为了加快浏览速度,web浏览器将网站数据的副本保存为一组称...

  • 发布于 2021-04-02 04:04
  • 阅读 ( 244 )

如何使用curl从linux命令行下载文件

...,所以现在有一个名为bbc.html.” 双击该文件将打开默认浏览器,以便显示检索到的网页。 请注意,浏览器地址栏中的地址是此计算机上的本地文件,而不是远程网站。 我们不必重定向输出来创建文件。我们可以使用-o(output...

  • 发布于 2021-04-02 22:46
  • 阅读 ( 197 )

如何在Windows10中启用剩余电池时间

...不是时间。虽然它有它的怪癖,你可能还是想看看它。 为什么微软隐瞒了电池寿命的估计? 这些信息被删除了,因为这只是一个估计。它可能会发生巨大的变化,这取决于正在运行的进程、屏幕的亮度以及您是连接到Wi-Fi还是...

  • 发布于 2021-04-03 18:39
  • 阅读 ( 165 )

为什么我的浏览器存储了这么多私人数据?

在浏览器历史记录和跟踪cookies之间,很容易感觉到你的浏览器正在跟踪和监视你。但是网络浏览器存储这些私有数据是有充分理由的。 我们已经向您展示了如何让您的浏览器在关闭或总是以私人浏览模式启动时清除私人数据。...

  • 发布于 2021-04-09 03:14
  • 阅读 ( 146 )

从系统托盘中快速更改windows中的默认web浏览器

...开发者还是一个狂热的互联网用户,你可能需要使用多种浏览器。每个浏览器都有其他浏览器无法提供的有用功能,因此,您可能需要切换浏览器以利用某些功能。 您只需从桌面或“开始”菜单打开所需的浏览器即可。但是,...

  • 发布于 2021-04-12 00:56
  • 阅读 ( 92 )
dajruvpiptehg
dajruvpiptehg

0 篇文章

相关推荐