datastar icon indicating copy to clipboard operation
datastar copied to clipboard

deno, node and deno-sw hello world examples

Open nickchomey opened this issue 11 months ago • 7 comments

Here's the deno, node and deno-sw typescript sdk examples.

I had to make local copies of the static assets for the deno-sw example, as I was having difficulty with caching and serving external resources. Likewise, the html doc is served from an ES Module that contains a template literal of the doc, as I was having a lot of issues with serving a static file as the root route ("/").

If you want/know how to fix any of that, feel free to suggest the required changes. Otherwise, I think its fine as-is for the sake of a demo.

nickchomey avatar Jan 30 '25 01:01 nickchomey

@Superpat this is ready for your review whenever you've got time

nickchomey avatar Jan 30 '25 01:01 nickchomey

I'm not sure I'll have time to review this until after Fosdem, but thank you !

Superpat avatar Jan 30 '25 09:01 Superpat

@nickchomey like I said in an earlier pr, I cant use the js version of esbuild on OpenBSD, so I cant review the sw bits. Can you switch the sw building code to use something like deno dnt instead ? Check the npm package build code, it's using deno dnt.

Superpat avatar Feb 05 '25 07:02 Superpat

Sure I'll figure out deno dnt

nickchomey avatar Feb 05 '25 11:02 nickchomey

@Superpat I got the static assets to load remotely now, tidied things up, and have provided a pre-built service-worker.js file as I wasted an hour trying to get DNT to work - its not worth the effort for this.

You can just run deno run start and it should just work. If you/anyone wants to modify the files and doesnt have esbuild available on their system, then they'll have to figure out a build system that works for them.

The only remaining "gotcha" is a couple second delay if your browser is still set to online, but the network request fails (eg deno is stopped) - it waits for that request to fail before falling back to service worker rendering. If you set the browser to offline, it goes there immediately. I could add some sort of background polling and a signal to pre-detect if the network/deno server is available, but that really isn't worthwhile for this proof-of-concept.

ps. note that I've removed the sdk/typescript/examples directory

nickchomey avatar Feb 05 '25 14:02 nickchomey

I will try to finish reviewing this before the weekend is over. Still recovering from my ssd meltdown last week.

Superpat avatar Feb 12 '25 18:02 Superpat

It's been 84 years

delaneyj avatar Mar 03 '25 21:03 delaneyj

It’s been a light year...

bencroker avatar Jun 06 '25 21:06 bencroker