我知道,为了在“ /”(Blazor Server中的wwwroot)以外的目录中注册Service Worker,我需要:
1)将范围添加到注册中:
navigator.serviceWorker.register('/static/mod/practice/service-worker.js', { scope: '/' })
.then(function (registration)
{
console.log('Service worker registered successfully');
}).catch(function (e)
{
console.error('Error during service worker registration:', e);
});
(来源Understanding Service Worker scope)
2)添加http标头Service-Worker-Allowed
(来源Understanding Service Worker scope和https://w3c.github.io/ServiceWorker/#service-worker-script-response)
问题:如何在Blazor Server项目中添加Service-Worker-Allowed
标头?