为什么浏览器即使在预加载后也多次加载音频文件? [英] Why does the browser load audio files several times even after preload?

查看:223
本文介绍了为什么浏览器即使在预加载后也多次加载音频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我们正在开发的Web App监视Safari移动网络上的网络,并且看到了以下内容:

i am monitoring the network on Safari mobile for a Web App we are developing and see this:

文件被预先加载(我想这就是为什么在三行的第一行中都显示(磁盘)"的原因),这是safari的网络检查器中网络"选项卡中的网络输出.

the files get preloaded before (I guess this is why it says "(disk)" in the first of the 3 lines), and this is the network output in safari's web inspector in the network tab.

现在,我想知道为什么浏览器似乎首先从磁盘加载它,然后又从URL加载两次(?).

Now I am wondering, why the browser seems to load it first from disk then two times(?) from the url again.

我看错输出了吗?

这样的预加载(在用户交互时)发生:

preloading happens like this (on user interaction):

function preloadAudio(url)
{
  console.log("trying to preload "+ url);
  var audio = new Audio();
  loadedAudioFiles.push(audio);

  audio.addEventListener('canplaythrough', loadedAudio, false);

  audio.src = url;
  audio.load();
  audio.onerror = function failed(e)
  {
    console.log(e);
    $("#NETWORKERROR").show();
  };
}

推荐答案

我应该更深入地研究

很难找到这个报价

注意:Safari 5.0和更高版本支持preload属性. iOS上的Safari永远不会预加载.

Note: The preload attribute is supported in Safari 5.0 and later. Safari on iOS never preloads.

来自: https://developer .apple.com/library/archive/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/AudioandVideoTagBasics/AudioandVideoTagBasics.html

尽管这句话似乎是错误的:我经常将预加载的音频文件放入系统中(在预加载功能运行后,通过切断连接进行检查,然后触发声音工作).但是Safari移动版似乎在做一些背景魔术来决定何时加载文件以及何时不加载文件. :-(

it seems even this statement is wrong though: I often get preloaded audio files into my system (checking by cutting the connection after the preload function ran and then triggering the sounds works). But Safari mobile seems to do some background magic to decide when to load files and when not. :-(

这篇关于为什么浏览器即使在预加载后也多次加载音频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆