Replies: 6 comments 14 replies
-
Beta Was this translation helpful? Give feedback.
-
It's worth adding in @jacob-ebey's example to the discussion... https://github.com/jacob-ebey/remix-pwa It uses the If it's not too much work, it would be useful to provide a manifest of all the static assets generated as part of the build ( Providing a function to register the SW seems more sensible than automatically registering it, as there might be different use-cases for how, and when to register the SW, for instance, as soon as a new one is available, or when the user clicks a button to update. Create React App provides some nice examples of this. Excited to see this come to life. |
Beta Was this translation helpful? Give feedback.
-
I used Response instance + entry.client to register install and uninstall service workers. https://remix.run/docs/en/v1/api/conventions#returning-response-instances I'm not aware of the best solution here, as it involve security and a bunch of stuff to be considered, bnut this worked for my case : create a route (in this case /sw)
------------ /app/entry.client.tsx -----------------
that is enough to be able to register an SW from the scratch, All the caching, uninstalling, etc still needs to be done. |
Beta Was this translation helpful? Give feedback.
-
I've been thinking about use-cases for server-side Service Workers. These are things that would be possible to implement in application-land, but much nicer to implement on a Plugin. A Plugin can only do these things, however, if it can intercept Shared CacheIf your server-side app makes upstream HTTP requests and runs on multiple servers/VMs, they would benefit greatly from a shared cache, say in Redis. Cache-Control MathYou have an app that uses HTTP to connect to upstream providers. A single page connects to multiple endpoints and composes data. Each upstream response includes some combination of Example: if |
Beta Was this translation helpful? Give feedback.
-
I'm using this configuration with Workbox and works really great:
Are you looking to generate this public file from routes instead? 🤔 |
Beta Was this translation helpful? Give feedback.
-
We are working trying to add some offline support to our app atm. Currently using https://github.com/remix-pwa/remix-pwa, and looks good One issue that we found is with some routes that contain actions, our intention is if the user is offline save a draft of the from in localStorage. the migration to this logic feels like breaking all the remix logic, moving a lot of logic to the route render of add custom loginc inside of our SW. Currently thinking if could be posible to have this can of api: // route file
export action = ({ context, request })=>{
// server action code
}
export loader = ({ context, request })=>{
// server loader code
}
export actionSW = ({ context, request, cache?})=>{
// code to be executed on sw as interceptor of this same route action
}
export loaderSW = ({ context, request, cache?})=>{
// code to be executed on sw as interceptor of this same route action
} this would expect to have the same code splitting that we have now with server-client but adding the sw to the equation |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Proposal
Add native support for Service Worker with an optional
entry.worker
file that Remix could compile to a SW and inject the setup into the HTML.Background
Service Workers (SW) is not only required to build a Progressive Web App (PWA), it can also be used for a lot of other features like Push Notifications, cache assets and even provide offline support by intercepting fetch requests to the server and cache them.
Right now you need manually code the SW inside the public folder and if you want some build process to share code between the app and SW you need to manually run esbuild on the SW and put the output on the public folder.
I think Remix could help here by providing an entry point for SW, by adding an
entry.worker.ts|js
file insideapp
it could detect that and build it.Additionally, it could either automatically register the SW or provide a function to do it in
entry.client
.By doing this it would be possible to share code between SW and the rest of the app.
Something that Remix could also do is provide a magic import to has access to the built files so the developer could use that to cache or pre cache those files.
Use Case
API/Examples
Create an
entry.worker.ts
file inapp
, together withentry.client.tsx
andentry.server.tsx
.Inside this file, you can code the SW as usual, but you can also import files from the build process.
To register the SW Remix could either add it to the output of
<Scripts />
or give a function that the developer could call inentry.client
Beta Was this translation helpful? Give feedback.
All reactions