GithubHelp home page GithubHelp logo

Comments (8)

segevfiner avatar segevfiner commented on June 2, 2024

Hmm, actually I probably need to add the RangeRequests plugin to the precaching handler... So that runtimeCachine example from the linked article isn't helpful for that...

from workbox.

segevfiner avatar segevfiner commented on June 2, 2024

Doesn't seem to help even if I do that though...

from workbox.

segevfiner avatar segevfiner commented on June 2, 2024

I guess a workaround will be to do preload="none" and hope the user doesn't start any media before pre-caching ends... There doesn't seem to be an obvious way to add plugins to workbox-precaching in generateSW mode of workbox-build which I opened a separate request for #3289.

I guess a fix will be to just let such requests through to the network, without trying to precache from their response, letting the normal pre-caching still take place, or alternatively to outright to dump the Range header when getting a request that has it during the install phase in the PrecachingStrategy, and maybe also pass the response through plugins so the ranges plugin can modify the complete response to only return the requested range even in that case.

from workbox.

segevfiner avatar segevfiner commented on June 2, 2024

Maybe we want something like this in the range requests plugin or inside workbox-precaching:

// requestWillFetch() if from a plugin
    if (handler.event && handler.event.type === 'install') {
      request.headers.delete("Range")
    }

from workbox.

segevfiner avatar segevfiner commented on June 2, 2024

Doesn't work. The headers received in the request object seem empty for this case...

from workbox.

segevfiner avatar segevfiner commented on June 2, 2024

We probably need to add 206 to be ignored here:

if (!response || response.status >= 400) {

from workbox.

segevfiner avatar segevfiner commented on June 2, 2024

Doesn't help, still leads to bad-precaching-response.

from workbox.

segevfiner avatar segevfiner commented on June 2, 2024

So basically the browser sets a Range: bytes=0- header with preload="auto" and gets a full response with a 206 status, when the service worker starts after that request is complete, and tries to prefetch the file, the browser returns the 206 full content response (Racy, due to chromium coalescing the requests) which fails to be inserted into the cache with the described error. Something like this can possibly fix this:

    async cacheWillUpdate({ response }) {
      // The default will update logic of workbox-precaching
      if (!response || response.status >= 400) {
        return null;
      }

      if (response.status === 206 /* && fullBody */) {
        console.log('Patching 206 response');
        response = await copyResponse(response, (responseInit) => {
          responseInit.status = 200;
          return responseInit;
        })
      }

      return response;
    },

But I think copyResponse will fail if the request is cross origin...

from workbox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.