Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cors image request retry not work #1488

Closed
QingLeiLi opened this issue Dec 6, 2019 · 2 comments
Closed

cors image request retry not work #1488

QingLeiLi opened this issue Dec 6, 2019 · 2 comments

Comments

@QingLeiLi
Copy link

I am investigating a usage scenario of ServiceWorker:

  1. Our static resources are hosted on the CDN. We have two CDN domain names, https://cdna.com and https: //cdnb/.com, and both have set the access-control-allow-origin header to *
  2. HTML loads an image on CDN https://cdna.com: <img src = "https://cdna.com/img.png">
  3. Due to DNS pollution, https://cdna.com/img.png failed to load
  4. Important: Can I switch the URL to https://cdnb.com/img.png and try again?

The ServiceWorker I run on chrome didn't give the resolved Response to the website, but the loading failed.

Could anyone tell me why this is, thanks in advance.

@QingLeiLi
Copy link
Author

A sample code:

self.addEventListener('fetch', function(e) {
  if(e.request.url === 'https://cdna.com/img.png'){
    return fetch(new Request('https://cdnb.com/img.png'));
  }else{
    return fetch(e.request);
  }
});

@QingLeiLi
Copy link
Author

Sorry, It is a mistake, I forgot to add e.respondWith

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant