跨域:缓存清单本身
Cross domain: the cache manifest itself
我最近着手构建一个 运行 在移动设备上完全离线的 Web 应用程序。
我们的设置是这样的:
- CMS 和 API 运行 关闭域 A 上的 EC2 服务器;
- 资产已发布到域 B 上的 S3 存储桶;
- Web 应用托管在域 C 上的 S3 静态网站存储桶上。
我无法跨域缓存清单本身(因为它是一个动态文件,其位置无法更改)。
如何在不更改 cache.manifest 文件位置的情况下缓存文件?
W3C says cross-domain 允许与清单一起使用:
The manifest-src and default-src directives govern the origins from which a user agent can fetch a manifest. As with other directives, by default the manifest-src directive is *, meaning that a user agent can, [CORS] permitting, fetch the manifest cross-domain. Remote origins (e.g., a CDN) wanting to host manifests for various web applications will need to include the appropriate [CORS] response header in their HTTP response (e.g., Access-Control-Allow-Origin: https://example.com).
您可以检查清单中是否存在 Access-Control-Allow-Origin
响应 header。例如:
HTTP/1.1 200 OK
[...]
Access-Control-Allow-Origin: http://example.com
[...]
我最近着手构建一个 运行 在移动设备上完全离线的 Web 应用程序。
我们的设置是这样的:
- CMS 和 API 运行 关闭域 A 上的 EC2 服务器;
- 资产已发布到域 B 上的 S3 存储桶;
- Web 应用托管在域 C 上的 S3 静态网站存储桶上。
我无法跨域缓存清单本身(因为它是一个动态文件,其位置无法更改)。
如何在不更改 cache.manifest 文件位置的情况下缓存文件?
W3C says cross-domain 允许与清单一起使用:
The manifest-src and default-src directives govern the origins from which a user agent can fetch a manifest. As with other directives, by default the manifest-src directive is *, meaning that a user agent can, [CORS] permitting, fetch the manifest cross-domain. Remote origins (e.g., a CDN) wanting to host manifests for various web applications will need to include the appropriate [CORS] response header in their HTTP response (e.g., Access-Control-Allow-Origin: https://example.com).
您可以检查清单中是否存在 Access-Control-Allow-Origin
响应 header。例如:
HTTP/1.1 200 OK
[...]
Access-Control-Allow-Origin: http://example.com
[...]