HTML视频流大小超过文件大小,如何使用JavaScript缓存和优化HTML视频元素?
我正在尝试从nodejs
服务器流传输视频,并且正常工作。但是问题在于视频尺寸为61MB。当我更改我的HTML视频元素中的范围时,它再次获取,如果继续,则导致循环和提取尺寸将超过100 MB。在视频满载并将流尺寸最大化为视频尺寸之后,如何不再加载视频?
I am trying to stream a video from a NodeJS
server and it is working fine. But the problem is with the video size, which is 61MB. As I change my range in the html video element it fetches again, which causes a loop and fetch size will exceed 100 mb if continued. How not to load the video anymore, after the video is fully loaded and keep stream size maximum to video size?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是问题。
浏览器正在尝试优化要获取的内容,并对视频的播放方式做出假设。理想情况下,它只想下载实际使用的视频,而不下载其他视频。
您需要对缓存行为进行更严格的控制。幸运的是,您可以使用 Service Worker 来完成此操作。可以构建 Service Worker 来拦截来自媒体元素的请求,并将范围内的请求一起缓存到单个资源中。如果稍后再次需要该资源,Service Worker 将控制直接从本地缓存获取该资源。
This is not a problem.
The browser is trying to optimize what to fetch, making assumptions about the way a video will be played. Ideally, it only wants to download the video that's actually used and no additional video.
You need tighter control over the caching behavior. Fortunately, you can do this with a Service Worker. The Service Worker can be built to intercept requests form the media elements, and cache ranged requests together into a single resource. If the resource is needed again later, the Service Worker will control fetching it directly from local cache.