Html 浏览器在什么情况下会缓存 <video> 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5111382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Under what conditions will the browser cache <video> files?
提问by Matrym
Under what conditions will the browser cache files? Sometimes it does, sometimes it doesn't. If no one here knows, my next step will be to test the various file format, file size, and htaccess scenarios.
浏览器在什么情况下会缓存文件?有时会,有时不会。如果这里没有人知道,我下一步将测试各种文件格式、文件大小和 htaccess 方案。
If you don't know, can you think of any other variables that you'd recommend testing?
如果您不知道,您能想到您建议测试的任何其他变量吗?
Thanks in advance!
提前致谢!
回答by Matrym
The following works to instruct the browser to cache the files. The last line was necessary to make the server deliver webm files with the correct header MIME type.
以下工作指示浏览器缓存文件。最后一行是使服务器传送带有正确头 MIME 类型的 webm 文件所必需的。
# Expires is set to a point we won't reach,
# Cache control will trigger first, 10 days after access
# 10 Days = 60s x 60m x 24hrs x 10days = 864,000
<FilesMatch "\.(webm|ogg|mp4)$">
Header set Expires "Mon, 27 Mar 2038 13:33:37 GMT"
Header set Cache-Control "max-age=864000"
</FilesMatch>
AddType video/webm .webm
回答by tagawa
The HTML5 spec is not strict about what a browser must do with caching video files - it just suggests what is "reasonable", so theoretically different browsers could have different behaviour.
HTML5 规范并没有严格规定浏览器必须对缓存视频文件做什么——它只是建议什么是“合理的”,因此理论上不同的浏览器可能有不同的行为。
Web developers can try to control video caching using the preload
attribute on the <audio>
or <video>
element like this:
Web 开发人员可以尝试使用或元素preload
上的属性来控制视频缓存,如下所示:<audio>
<video>
preload=none
The user might not watch the video (i.e. better not to preload)
preload=none
用户可能不会观看视频(即最好不要预加载)
preload=metadata
The user might watch the video (i.e. better to just download information about the video (size, duration, etc.))
preload=metadata
用户可能会观看视频(即最好只下载有关视频的信息(大小、持续时间等))
preload=auto
The user is likely to watch the video (i.e.probably a good idea to preload and cache the video)
preload=auto
用户可能会观看视频(即预加载和缓存视频可能是个好主意)
As I said, the spec does not enforce this so browsers could ignore the preload values if they choose. One example could be if a browser detects a slow or unstable connection and therefore refuses to preload, although I don't know of any browsers that do this at present.
正如我所说,规范没有强制执行这一点,因此浏览器可以选择忽略预加载值。一个例子可能是浏览器检测到缓慢或不稳定的连接并因此拒绝预加载,尽管我目前不知道任何浏览器会这样做。
More information on the preload attribute is here: http://www.w3.org/TR/html5/video.html#attr-media-preload
关于 preload 属性的更多信息在这里:http: //www.w3.org/TR/html5/video.html#attr-media-preload