Skip to content

Full offline support, precacheConfig vs prerender-urls.json etc... #475

@mariusk

Description

@mariusk

I'm struggling with getting full offline support operational. The use case is full offline support after first load on a mobile device. The application runs as a single page app, but I'm using the automatic feature of react-cli that creates separate files for the routes in my app.

Specifically I'm struggling with what I actually have to do to get everything pre loaded the first time my app is loaded. My test case is loading the app, the going offline (flight mode) and trying to navigate to another screen.

Exactly how and where does preact-cli know which routes to pre-render (and pre-load / cache I guess)? I'm using preact-cli-sw-precache where I'm trying to set everything automatically with a configuration like:

  const precacheConfig = {
    staticFileGlobs: [
      'build/**/*.{html,js,css,jpg}',
      'build/assets/favicon.ico',
      'build/assets/icons/*.png'
    ],
    stripPrefix: 'build/',
    navigateFallback: '/index.html',
    runtimeCaching: [{
      urlPattern: /\/api\//,
      handler: 'networkOnly'
    }, {
      urlPattern: '.*',
      handler: 'cacheFirst'
    }],
    minify: true,
    clientsClaim: true,
    skipWaiting: true,
    maximumFileSizeToCacheInBytes: 10*1024*1024
  };

Is this enough for the build system to figure out all the routes (disregarding the details about how this gets set up in preact.config.js, or do I need to specify a list or urls in the prerender-urls.json file in addition? And if so, how can I specify routes with "url based parameters", like logid in:

[
  {url: "/profile", title: "Profile"},
  {url: "/edit/:logid", title: "Log Edit"}
]

My gut feeling says only one of these should be necessary, but I can't get it working, so any help would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions