I have enabled CORS by adding below to webconfig but it doesnt seems to work consistently:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
If we add an "Origin" header in the request, it does show Access-Control-Allow-Origin:* headers in response. But if we don't add "Origin" header in the request, the server doesn't return Access-Control-Allow-Origin:* headers.
The issue is, I am using sw-toolbox to precache static resources. But if a resource such as javascript files is already in browser cache before service worker is activated, for example the file is directly referenced in the html page and browser has already downloaded and cached the file, it shows CORS error when service worker tries to precache that file.