ilan-schemoul / meteor-service-worker

An universal service worker for meteor apps
MIT License
137 stars 26 forks source link

Image files not loading #1

Closed justindra closed 7 years ago

justindra commented 7 years ago

So the first time I load the page, it works perfectly, but then if I hit refresh, some images do not load (these are loaded from a different subdomain).

Fetch API cannot load http://sub.domain.com/images/image.jpg. Failed to start loading.
The FetchEvent for "http://sub.domain.com/images/image.jpg" resulted in a network error response: an object that was not a Response was passed to respondWith().
ilan-schemoul commented 7 years ago

Hello, I can't give you right now a fix because it's too late here but I think I got the problem : as each subdomain is considered as a new origin we need to have to deal with Cross-Origin Resources https://www.w3.org/TR/service-workers/#cross-origin-resources

justindra commented 7 years ago

Cool! Thanks for that info. I will have a go and see if I can fix it as well.

ilan-schemoul commented 7 years ago

First, as I can't access anything but my phone I can't test anything. But I made some search and here's what I come up with. There is three reponse.type : basic, cors and opaque. If you fetch from same origin the response.type is basic. Otherwise it's either cors or opaque. You probably do not want opaque as we can't read data from it. So cors seems to fits for you case and accordingly to google to have cors type you just need to return a cors header. So could you check if you subdomain return propers CORS headers and if all is in https (mandatory for service worker)

justindra commented 7 years ago

So it is returning proper CORS headers. Although, the subdomain where the images are, are not on a https subdomain. I will see if I can update that.

ilan-schemoul commented 7 years ago

I'm actually surprised of that, I tought load assets from a subdomain which is not https to a domain which is have HTTPS wasn't possible (I mean I experience that problem where I secure my main domain but not my subdomain). And I assume your main domain have HTTPS otherwise SW doesn't run.

justindra commented 7 years ago

Yep, so my main domain has HTTPS, and my subdomain was a cname to an S3 bucket which turns out does not forward through the ssl cert. So I've changed it back to use the S3 bucket url provided, which is https and that seems to fix the problem.

So I guess this isn't actually a problem with CORS. I will close for now.