svimanet / blockit

A simple static web game made for fun and hosted on GH pages
https://svimanet.github.io/blockit/
MIT License
0 stars 1 forks source link

[Feature request] Offline support. #4

Open nenadalm opened 1 day ago

nenadalm commented 1 day ago

PWA currently doesn't work offline:

Screenshot_20241114-184529

since it seems it doesn't communicate with any server, it would be nice if it was possible to play offline.

svimanet commented 16 hours ago

Thanks for the input. I've looked a bit at this, since I was fairly certain I had supported and tested this already.

After re-testing, I am able to reproduce the issue, only if I have not recently opened the app, and enabled flightmode before I opened it. If I open the app with internet connection, close it, enable flight mode, and re-open the app, it works. Seems to be an issue with the caching policy on the current hosting solution (Github Pages).

https://github.com/orgs/community/discussions/11884 Found an open issue about this, where it seems GH pages has a cache-lifetime of 10 minutes, that I will put up as a blocker for this issue.

I currently do not have plans to switch hosting services, since I do not want to maintain a server and/or pay for hosting. Though who know what I feel like doing next year. I've gotten tons of IRL feedback to add a hiscores feature, which would also require some server-validation logic for POSTs.

BUT, this should be fairly easy to host on any server for private caching, since it's just a static website with standard structure. So I encourage you to set up hosting on a private server somewhere, for you and your friends to enjoy better offline support.

nenadalm commented 16 hours ago

I think the github pages caches shouldn't be a problem. I have a few of my pwas like backgammon (https://github.com/nenadalm/backgammon/blob/master/resources/private/worker.js) there and I don't experience such issue. I cache every asset in my service worker.

nenadalm commented 16 hours ago

It looks like caching is not working (tested in Chrome) due to missing files:

20241115_10h47m23_grim

svimanet commented 16 hours ago

hmm, you might be right. I'll take a closer look after work. On first glance it looks like the the serviceworker script does not use the generated-names for assets. I have another TODO for fixing bundling and deployment, so I might try hitting two birds with one stone