缓存是否适用于部分加载的文件?
这不是一个“编码问题”,而更像是“它是如何工作的?”。
让我们考虑一下我想在第 2 页上显示一张厚重的图片。 如果我在第 1 页上预加载此图片(无显示),并在完全加载之前单击第 2 页链接...会发生什么?
=>第 2 页加载,并且重图片的结尾也加载,或者缓存对部分加载的文件不起作用?
谢谢你的解释,
CH
This is not a "coding question", but more something like "how does it work?".
Let's consider I want to show an heavy pic on page 2.
If I'm preloading this pic on a page 1 (no display) and click on the page-2-link before it's fully loaded... What happens?
=> The page 2 loads and the end of heavy pic is also loaded, or cache doesn't work for partially loaded files?
Thanks for your explanations,
CH
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
理论上,部分响应很可能被 Web 浏览器或最终用户和 Web 服务器之间的代理服务器缓存。 http 支持范围请求,客户端可以请求总资源的特定部分(例如图像)。所有知名 Web 服务器都支持范围请求。
我真的不知道是否有任何网络浏览器缓存部分下载的资源,尽管这将是一个简单的测试 - 清除网络浏览器缓存,点击加载大型外部对象的网页,中途停止加载。确保网络服务器随响应一起发送以下标头。
现在再次发出请求,但查看请求的 http 标头,以查找浏览器请求部分内容的情况,例如
Range: bytes=100000-90000000
。如果它部分缓存了文件,它显然只会要求部分内容。max-age 标头告诉浏览器该文件可以缓存一段时间,accept-ranges 标头告诉浏览器 Web 服务器能够为部分内容请求提供服务。
In theory its very possible that part of the response gets cached, either by the web browser or by a proxy server between the end user and the web server. http supports range requests, where the client can ask for a specific slice of the total resource(like an image). All the big name web servers support range requests.
I really don't know off hand if any web browsers cache a partially downloaded resource, although it would be a simple test - clear the web browsers cache, hit a web page that loads a large external object, stop loading midway through. Make sure the webserver sends the following headers along with the response.
Now make the request again but look at the http headers of the request to look for the browser asking for partial contents like
Range: bytes=100000-90000000
. It would obviously only ask for partial content if it had partially cached the file.The max-age header tells the browser the file is cachable for a while, and the accept-ranges headers tells the browser the web server is capable of servicing partial content requests.