CreateJS/PreloadJS

PreloadJS and Service Worker

Closed this issue · 2 comments

I am trying to use service worker with PreloadJS. I have cached the images required and then loading them using the caches.match() function.

When I try to load the image with jquery it works fine, but on loading with preloadJS it gives the following error

The FetchEvent for "someurl" resulted in a network error response: an "opaque" response was used for a request whose type is not no-cors

Although if I load any other image that isn't cached, PreloadJS loads that image properly. The problem is occuring only when I use caches.match.

What might be the reason for this ?

Load Image using preloadjs

var preload = new createjs.LoadQueue();

function loadImageUsingPreload() {

  preload.on('complete', completed);

  preload.loadFile({ id: 'someid', src: 'someurl', crossOrigin: "Anonymous" })

};

function completed() {
  var image = preload.getResult("someid");
  document.body.append(image);
};

Load Image using jquery

function loadImageUsingJquery() {
  jQuery("#image").attr('src', 'someurl');
};

Service Worker fetch event

self.addEventListener('fetch', function(event) {
  event.respondWith(
    caches.match(event.request).then(function(response) {

      if (!response) {
        console.log('fetching...' + event.request.url);
        return fetch(event.request);
      };
      console.log("response", response);
      return response;
    }));
});

The response object when I load using PreloadJS or jQuery:

Response {type: "opaque", url: "", redirected: false, status: 0, ok: false, …}

I have the same issue.
Why did you close it @formatkaka ? You found a solution?
Best regards,
Emmanuel

Hey @emmanuelgeoffray

Please refer to this StackOverflow answer -

Regards,
Siddhant