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

offline support #893

Closed
mfulton26 opened this issue Nov 10, 2022 · 8 comments
Closed

offline support #893

mfulton26 opened this issue Nov 10, 2022 · 8 comments

Comments

@mfulton26
Copy link

I'd like to be able to use Fresh offline. My users are in rural areas throughout the day. Sometimes they have a strong internet connection and sometimes they do not. I want to bundle my entire Fresh app to run offline via a service worker. From what I can tell, the handler() in Fresh's ServiceContext should be able to be used to take a Request from a service worker's FetchEvent and compute a Response. The esbuild runtime should be usable to bundle the service worker too (see also #858).

@ccssmnn
Copy link

ccssmnn commented Jan 9, 2023

This sounds like a perfect use case for a Single Page Application. You ship the HTML, one (or more with code-splitting) bundle of JavaScript and CSS and maybe a service worker. The app will talk to the API's directly or through the service worker. It's all there.

Why bother using Fresh & the Island Architecture in a service worker?

@mfulton26
Copy link
Author

A Single Page Application (SPA) may certainly be more ideal than a Multiple Page Application (MPA) but either way being able to write the application with Deno rather than Node and avoid needing to use Webpack, etc. are the top things I'm looking for.

One downside of a SPA is that larger apps suffer from high memory usage. I do not know of a way in JavaScript to remove code from memory once loaded (short of the ShadowRealm API which is currently a proposal in Stage 3). So even with code splitting once you move around the app and have loaded more and more bundles you're now consuming potentially a lot of memory. I'm not certain if this is the cause of some of the performance issues I've seen with apps I've worked in though.

What I think would be ideal though is to define an app that runs on the edge (e.g. Deno Deploy) and then be able to reuse a bunch of that app's route code via a service worker. Fresh might not be the answer but it is the only Deno-based web UI framework that I know of with meaningful adoption.

I could see a service worker dynamically loading whichever route code is needed when a request is made for a route or, if the app is small enough, keeping everything in memory more like code running on the edge.

@ccssmnn
Copy link

ccssmnn commented Jan 10, 2023

With regard to using Deno instead of node for developing your SPA I am setting this up in ccssmnn/relaxed-spa (demo: https://relaxed-spa.deno.dev) as a simple starting point. The goal is to develop client and server code in one Deno project with minimum boilerplate.

It reuses the JIT client code bundling from fresh as well as the reloading mechanism on server restart.

@mfulton26
Copy link
Author

Something else that building the Fresh handler for offline usage gives over a SPA PWA solution is true dynamic routing and pages. With a SPA any data driven content has to be done during hydration whereas I want to minimize/reduce JavaScript in the document window and would prefer to fetch/load the data inside the service worker and then serve up to the document window dynamic content on demand.

@marvinhagemeister
Copy link
Collaborator

Closing as duplicate of #893

@HelloFillip
Copy link

Closing as duplicate of #893

This is #893 @marvinhagemeister.

Using something akin to Workbox.js feels more inline with Fresh than depending on an single-page application (SPA). This is the route I've been taking, but I'd like to see this as a recipe for Fresh to support real progressive isomorphic web applications, which Fresh seems well suited for.

@marvinhagemeister
Copy link
Collaborator

Closing as duplicate of #893

This is #893 @marvinhagemeister.

Whoops 😅

@marvinhagemeister
Copy link
Collaborator

Closing as it's not something we're planning to do.

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

4 participants