【问题标题】:XMLHttpRequest really slow on Google ChromeXMLHttpRequest 在 Google Chrome 上真的很慢
【发布时间】:2016-08-01 20:02:09
【问题描述】:

我昨天一直在做一个新的小项目:www.mexicans.eu。一个只做一件事的网站:播放墨西哥歌曲 Jarabe。页面中间有一扇门,可以点击打开或关闭门。关上门会为墨西哥歌曲设置一个过滤器。那里只是一些基本的网络音频。

问题在于谷歌浏览器的加载时间。

_loadDoorSound: function(url, onload) {
  var startTime = new Date().getTime();

  var request = new XMLHttpRequest();
  request.open('GET', url, true);
  request.responseType = 'arraybuffer';

  request.onload = function() {
    var loadTime = new Date().getTime() - startTime;
    console.log("Loaded sound in " + loadTime + " milliseconds");

    console.log("Decoding sound");
    this.ctx.decodeAudioData(request.response, function(buffer) {
      this.AUDIO.buffer = buffer;
      this.onload();
      console.log("Decoded sound");
    }.bind(this));
  }.bind(this);

  console.log("Loading sound");
  request.send();
}

谷歌浏览器的加载时间平均为 14 秒。在 Firefox 中,它平均约为 300 毫秒。

但是。当我在本地提供页面时,谷歌浏览器加载它的速度非常快,与 Firefox 一样快。但是为什么谷歌浏览器在从服务器加载声音时会这么慢呢?

PS:由于 IE 不支持 Webaudio API,并且出于未知原因,对于 Safari,该网站还不能用于 Internet Explorer。

【问题讨论】:

    标签: javascript google-chrome xmlhttprequest


    【解决方案1】:

    我找到了。这只是一个缓存问题。在 Firefox 中清除缓存后,我的加载时间与 Google Chrome 中的加载时间大致相同。

    【讨论】:

      猜你喜欢
      • 2017-02-27
      • 2020-07-29
      • 1970-01-01
      • 2015-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-10
      相关资源
      最近更新 更多