I've searched a lot and everything I found was that service worker file should be on same domain as app.js file due to security reasons. Is there any way to register it with url or embed sw.js into app.js? registering looks like this:
navigator.serviceWorker.register('sw.js')
.then(function (swReg) {
app.js script is connecting to site with url
<script type="text/javascript" src="https://example.com/preform/app.js" ></script>
if I connect it on another domain (example.net) it is trying to register sw.js with path like this:
example.net/sw.js/, not example.com/preform/sw.jsso there is 404 error.
if I paste url in serviceWorker.register
navigator.serviceWorker.register('https://example.com/preform/sw.js')
.then(function (swReg) {
I have error:
Service Worker Error DOMException: Failed to register a ServiceWorker: The origin of the provided scriptURL ('https:// example.com') does not match the current origin ('https://example.net').
What should I do? app.js script should be linked for a lot of sites so it's dumb to upload sw.js to every site. If there is a way