XMLHttpRequest 在 Google Chrome 上真的很慢
XMLHttpRequest really slow on Google Chrome
我昨天一直在做一个新的小项目:www.mexicans.eu。一个只做一件事的网站:播放墨西哥歌曲 Jarabe。页面中间有一扇门,点击可以打开或关闭门。关上门会过滤掉墨西哥歌曲。那里只有一些基本的网络音频。
但问题是 Google Chrome 中的加载时间。
_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();
}
Google Chrome 的加载时间平均为 14 秒。在 Firefox 中,它平均大约 300 毫秒。
不过。当我在本地提供页面时,Google Chrome 加载速度非常快,与 Firefox 一样快。但是为什么从服务器加载声音时 Google Chrome 这么慢?
PS:由于 IE 不支持 Webaudio API,因此该站点对于 Internet Explorer 根本无法运行,并且由于未知原因而不支持 Safari。
我找到了。这只是一个缓存问题。在 Firefox 中清除缓存后,我得到的加载时间与 Google Chrome.
大致相同
我昨天一直在做一个新的小项目:www.mexicans.eu。一个只做一件事的网站:播放墨西哥歌曲 Jarabe。页面中间有一扇门,点击可以打开或关闭门。关上门会过滤掉墨西哥歌曲。那里只有一些基本的网络音频。
但问题是 Google Chrome 中的加载时间。
_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();
}
Google Chrome 的加载时间平均为 14 秒。在 Firefox 中,它平均大约 300 毫秒。
不过。当我在本地提供页面时,Google Chrome 加载速度非常快,与 Firefox 一样快。但是为什么从服务器加载声音时 Google Chrome 这么慢?
PS:由于 IE 不支持 Webaudio API,因此该站点对于 Internet Explorer 根本无法运行,并且由于未知原因而不支持 Safari。
我找到了。这只是一个缓存问题。在 Firefox 中清除缓存后,我得到的加载时间与 Google Chrome.
大致相同