我尝试fetch了旧网站的网址,发生了错误:
Fetch API cannot load http://xyz.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://abc' is therefore not allowed access.
If an opaque response serves your needs, set the request's mode to 'no-cors'
to fetch the resource with CORS disabled.
Run Code Online (Sandbox Code Playgroud)
我理解了该消息,并尝试执行返回不透明响应的请求:
fetch("http://xyz", {'mode': 'no-cors'})
Run Code Online (Sandbox Code Playgroud)
好吧,它现在有效...但我无法阅读它.= \
那么,不透明的反应的目的是什么?
Sal*_*lva 139
考虑服务工作者充当不可知缓存的情况.您唯一的目标是提供从网络获得的相同资源,但速度更快.当然,您无法确保所有资源都是您的原始资源(例如,考虑从CDN提供的库).由于服务工作者有可能改变网络响应,因此您需要保证您对响应的内容,标题,甚至结果都不感兴趣.你只对作为黑盒子的响应感兴趣,可以缓存它并更快地提供它.
这就是{ mode: 'no-cors' }为此而做的.
| 归档时间: |
|
| 查看次数: |
112803 次 |
| 最近记录: |