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
  • !2808

Offline-First Considerations: index.html caching

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/Enselic/master into master Jul 18, 2017
  • Overview 3
  • Commits 1
  • Pipelines 0
  • Changes 1

Created by: Enselic

If using CloudFront you should not cache index.html. Otherwise an old index.html might get populated in the cache for a new service-worker.js. That does not get recovered until a new service-worker.js is deployed.

Step-by-step:

  1. create-react-app sw-cache-problems ; cd sw-cache-problems
  2. npm run build
  3. mv build cloud-front-simulation
  4. perl -pi -e 's/To get started/BANANA/g' src/App.js
  5. npm run build
  6. serve -s cloud-front-simulation/ # And keep it running while continuing below
  7. Go to http://localhost:5000 in e.g. Google Chrome and observe 'To get started' appearing on the page
  8. Close the browser
  9. mv build/service-worker.js cloud-front-simulation/service-worker.js # We wait with index.html, pretending it is still cached in CloudFront
  10. cp -r build/static cloud-front-simulation/
  11. Go to http://localhost:5000 again
  12. You will notice in Console "New content available; please refresh" so do that. However, you still get the old index.html of course
  13. Close the browser
  14. mv build/index.html cloud-front-simulation/index.html # To simulate CloudFront cache experied and it fetched the new version
  15. Go to http://localhost:5000 again
  16. If you press F5 you get the old site (with 'To get started'). If you press Shift+F5 you get the new site (with 'BANANA') since you bypass SW . That's because the sw cache was populated while index.html was still old. And now we're stuck like this until a new service-worker.js is deployed
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/Enselic/master