Jun*_*ior 5 javascript google-chrome html5-audio service-worker
我有这样的声音:
var sound_obj = document.createElement("audio");
sound_obj.src = "../sounds/clic.mp3";
sound_obj.volume = 0.10;
sound_obj.autoPlay = false;
sound_obj.preLoad = true;
sound_obj.type = 'audio/mpeg';
document.addEventListener("click", function(){
sound_obj.play();
});
Run Code Online (Sandbox Code Playgroud)
一切都在所有浏览器上运行良好。但是在 Chrome 中,我看到每次点击时,Chrome 都会从站点请求 favicon.ico。每次。我做错了什么?
GET "https://mysite/favicon.ico".
Run Code Online (Sandbox Code Playgroud)
稍后编辑
它似乎与使用服务工作者('fetch')有关。这是我的版本:
const VERSION = 10;
const CACHE_NAME = 'mysite-cache-v-' + VERSION;
self.addEventListener('fetch', event => {
// Let the browser do its default thing
// for non-GET requests.
if (event.request.method != 'GET') return;
// Prevent the default, and handle the request ourselves.
event.respondWith(async function() {
// Try to get the response from a cache.
const cache = await caches.open(CACHE_NAME);
const cachedResponse = await cache.match(event.request);
if (cachedResponse) {
// If we found a match in the cache, return it, but also
// update the entry in the cache in the background.
event.waitUntil(cache.add(event.request));
console.log("cache fetch");
return cachedResponse;
}
console.log("fresh fetch "+ event.request.url);
// If we didn't find a match in the cache, use the network.
return fetch(event.request, {credentials: 'same-origin', redirect: 'manual'});
}());
});
Run Code Online (Sandbox Code Playgroud)
在 Firefox 中一切正常,但在 Chrome 中我看到浏览器favicon.ico在每次点击时都在获取。如果我使用 绕过 Chrome 中的 service worker Bypass for network,一切正常。我不知道这里出了什么问题。
这似乎是 Chrome 中的一个错误。您可以在这里找到参考: https://bugs.chromium.org/p/chromium/issues/detail ?id=1069731&q=favicon&can=2
您可以在此 Mozilla 页面上看到它的运行情况: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio
| 归档时间: |
|
| 查看次数: |
815 次 |
| 最近记录: |