Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sltt-app): runtimeCaching of requests absent #39

Open
ericpyle opened this issue Oct 23, 2024 · 1 comment
Open

fix(sltt-app): runtimeCaching of requests absent #39

ericpyle opened this issue Oct 23, 2024 · 1 comment

Comments

@ericpyle
Copy link
Collaborator

ericpyle commented Oct 23, 2024

The PWA has this runtimeCaching of requests that is absent from sltt-app because it does not run the service worker (primarily because it handles its own updates, and already has its own static assets installed).

One approach would be to try to get vitePWA service worker logic working on sltt-app (electron). See my outstanding question about this here: https://discord.com/channels/937808017016119440/937973377883336704/1298750422575480864

For electron, we don't need caching for static assets and we don't need to check for service worker updates (since in both cases the latest should be in the installed package, and sltt-app has its own auto-update mechanism)

If we aren't able to easily get the vitePWA service worker to do the same thing for us in sltt-app (electron), we may consider other approaches:

  1. uses caches directly for each of these requests so both PWA and sltt-app work the same way
  2. do something different in sltt-app with its own proxy.

I (eric) am leaning toward 1. (See ApiDotBible.ts putToCache() as an example where the PWA is doing this)

        runtimeCaching: [
          /* port from sw-template.js */
          {
            /*
             * NOTE: This probably has no effect, because it needs a full s3 path to work 
             * (see slttresources note below) but we're using a localStorage.setItem('projects') for now
             */
            urlPattern: /projects$/,
            handler: 'CacheFirst',
            options: {
              cacheName: 'projects',
            },
          },
          // /* woff, woff2, ttf already covered by globPatterns */
          // {
          //   urlPattern: /\.(?:woff|woff2|ttf)$/,
          //   handler: 'CacheFirst',
          //   options: {
          //     cacheName: 'fonts',
          //   },
          // },
          {
            urlPattern: /sdb[gh]s\.json$/,
            handler: 'CacheFirst',
            options: {
              cacheName: 'sdbghs',
              expiration: {
                // These are biggish. Update once a week.
                maxAgeSeconds: 7 * 24 * 60 * 60, // 1 week
              },
            },
          },
          {
            /**
             * Because we are fetching things from a bucket that is not the same as the application
             * bucket we must write a regular expression that matches from the start of the url.
             * See: https://developers.google.com/web/tools/workbox/modules/workbox-routing
             * (Matching and Handling in Routes)
             */
            urlPattern: /https:\/\/s3.amazonaws.com\/sltt-resources.*\.json$/,
            handler: 'CacheFirst',
            options: {
              cacheName: 'slttresources',
              expiration: {
                maxAgeSeconds: 24 * 60 * 60, // 1 day
              },
            },
          },
        ],
@ericpyle
Copy link
Collaborator Author

For electron I need to set the start_url like so:

manifest: {
        start_url: './',

And to make sure <ServiceWorkerWrapper> is called even for sltt-app builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant