Code Monkey home page Code Monkey logo

Comments (4)

jeffposnick avatar jeffposnick commented on July 28, 2024

My current thinking, after experimenting a bit in the https://github.com/jeffposnick/gulp-sw-precache project:

  • Define groups of resources:
    • Generally, use glob patterns based on file extensions.
    • Within the set of files that match a certain pattern, identify "volatile" files that are most likely to change and create a distinct group for those. E.g. all the bower_components/**.js files are unlikely to change, while the scripts/**.js files are much more likely to.
  • Each group of resources will be stored in an individual service worker Cache object. The Cache will be named/versioned based on a combination of the group identifier + a hash of each file's contents. If any of the files that make up a group change, the entire Cache gets invalidated and all of the files in that Cache will be refetched.
  • To prevent accidentally pulling down, e.g., 10MB of image data in the install handler when a user first visits a page, impose an upper limit on the size of each cache (likely: 1MB) as well as a limit on the number of files in each (likely: 100 files). This is more of a sanity check than anything else.

shed doesn't offer flexibility with regard to naming and versioning individual caches, so we're going to have to go bare-metal service worker for the implementation.

from ioweb2015.

ebidel avatar ebidel commented on July 28, 2024

Is 1MB too small though? A few of the site's images alone will fill that up.

from ioweb2015.

jeffposnick avatar jeffposnick commented on July 28, 2024

I've been talking to some of the service worker eng. folks about this, and they confirmed that there's no technical reason why we can't maintain distinct, named caches for each individual resource. There might be a marginal slowdown when it comes to looking up entries, but we'd get the benefit of only expiring resources that change, without incurring the penalty of refetching unchanged resources that happened to be grouped together in the same cache.

I'm going to go with that approach, which is conceptually the same thing as what I implemented in https://github.com/jeffposnick/gulp-sw-precache, except that the group size would always be 1.

from ioweb2015.

jeffposnick avatar jeffposnick commented on July 28, 2024

FYI, I just added support for using a dedicated cache for each resource URL (GoogleChromeLabs/sw-precache@e7f91e7) and support for versioning server-generated resources based on all the component template files (GoogleChromeLabs/sw-precache@1e4aa51) into the gulp-sw-precache project.

It seems to work there, and accomplishes everything we need (I think), so I'm now going to port it all into this project.

from ioweb2015.

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.