在跨域Web应用程序中使用服务工作者

时间:2019-06-06 13:36:08

标签: javascript cross-domain service-worker

我有一个普通域(例如example.com),这是客户端的主要入口点,所有静态文件都从该域提供。但是,所有服务器数据终结点都在子域(api.example.com)上。我有一个用于缓存/预缓存静态文件的简单服务工作者,现在我希望将其扩展到缓存/预缓存数据。我使用了how to register a service worker from different sub domain中提到的隐藏iframe技巧。但是,即使它正确注册,并且即使我从api.example.com导航也可以缓存ajax调用,但是当我执行从example.com到api.example.com的ajax调用时(所有的CORS都很好,很花哨)api上的SW .example.com不会拦截/缓存这些请求。这是意料之中的,还是我某个地方可能有错误?

来自https://example.com/index.html

<iframe src="https://api.example.com/__sw_api.html" hidden sandbox="allow-scripts allow-same-origin"></iframe>

0 个答案:

没有答案