admin管理员组文章数量:1431691
As we know service worker is registered from the root of the project folder but, is there any way to fetch some static resources (css, js) from different domain(s)?
Example :
myWebsite
// main url (e.g. index.html)abc/css/style.css
// css file pathxyz/js/jsFile.js
//javascript file path
As we know service worker is registered from the root of the project folder but, is there any way to fetch some static resources (css, js) from different domain(s)?
Example :
myWebsite.
// main url (e.g. index.html)abc./css/style.css
// css file pathxyz./js/jsFile.js
//javascript file path
2 Answers
Reset to default 6Any request that es from the page (except iframe sub-resources) will pass through the service worker. These resources can be from the same or different origin. You can cache these resources so that they are available offline however as a developer you can't manipulate or inspect the contents of them unless the resources have the correct CORS header set.
For example, in your install event, you can Cache a remote file that is not on your domain.
self.addEventListener('install', function(e) {
e.waitUntil(
caches.open('airhorner').then(function(cache) {
return cache.addAll([
'https://paul.kinlan.me/'
]);
})
);
});
It is by default possible to fetch and cache cross-origin resources according to the specification:
the [cross-origin] objects stored are Response objects with the type attribute set to "opaque" [...] less expressive API than Responses typed "basic"; the bodies and headers cannot be read or set, nor many of the other aspects of their content inspected
本文标签: javascriptHow to use serviceworker if resources are on different domainsStack Overflow
版权声明:本文标题:javascript - How to use service-worker if resources are on different domains? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745592525a2665285.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论