Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !2438

Add cache invalidation based on service work url

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/ro-savage/service-worker-cache-invalidation into master Jun 01, 2017
  • Overview 3
  • Commits 4
  • Pipelines 0
  • Changes 4

Created by: ro-savage

Addresses some of the issues raised in #2398 (closed)

Specifically, that service workers are

  • Showing the wrong page when a non-CRA app is hosted at the same url + port, with manually deleting the SW the only way to fix it.
  • Showing an old CRA project if you are hosting a new on at the CRA on first visit. When refreshed the new project will show.

This adds the following checks when using service workers to fix these issues

  • Check if service worker already exists
  • If no service work, add service worker
  • If service worker is found, check the serviceworker url.
  • If its finds a 200 ok at the url. Then use the service worker as normal. (Same app)
  • If it doesn't doesn't get a 200 ok. Then check if the domain is working.
  • If domain responses with 200 ok. Then remove service worker and refresh the page (different app)
  • If anything else. Assume domain or user is offline and used service worker to provide cache.

For this to work properly, we'd need to give the service-worker.js a unique name such as service-worker-[projectname].js. This way each project as a unique service worker URL and we can tell if we are using the correct service worker.

For the webpack setup, we can just create a customer name for the generated the service worker using (service-worker-${packageName}].

For the registerServiceWorker.js we create an environment variable that contains the projects package.json name, and use this to know the right file to look for.

@gaearon @Timer @jeffposnick - Any ideas how we can name/rename the service-worker.js?

  • Make it work
  • How to correctly name service-worker.js
  • Think of edge cases and how to handle them - Currently handles offline and website down
  • How big is the slowdown in using fetch before we load the service worker? Especially if we are offline.
  • Is the a quicker way to tell if a device is offline? If offline we should catch immediately
  • Tests?
  • Are there other ways to deterministically tell what project a cached service worker is attributed to?
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/ro-savage/service-worker-cache-invalidation