Skip to content

Added functionality to automatically save board states in localStorage#103

Closed
EliDoris wants to merge 3 commits intox-sheep:mainfrom
EliDoris:caching
Closed

Added functionality to automatically save board states in localStorage#103
EliDoris wants to merge 3 commits intox-sheep:mainfrom
EliDoris:caching

Conversation

@EliDoris
Copy link

@EliDoris EliDoris commented Nov 22, 2025

Updated Boot.js to do caching in localStorage. This is basically the implementation that penpa uses, except:

  1. I used the encodings already available from the functionality that duplicates the board and the functionality that correlates URL to puzzle. It creates a new URL that incorporates the whole board state then correlates the "search" part of the URL with the "search" part of the base URL.
  2. It does not fire on the beforeunload browser event. I noticed that the visibilitychange event was firing at pretty much any time I could imagine wanting to cache, and upon further investigation it seems beforeunload is only really recommended when there is a desire to bring up a dialog and allow the user to cancel their decision to leave

This was tested and works perfectly on Chrome Version 142.0.7444.163 (Official Build) (64-bit). I don't really know what the best way is to go about testing on other browsers, but the code as written should be able to discern if there is no localStorage available and simply not do the caching in that case.

I also tested it for a simple loop up to 75x75, which has a pretty long encoding, and it was fine. Upon inspection, it looks like this fairly extreme case gives me ~67,000 characters in the URL. The base URL is considerably shorter, so this encoding is like <0.2 MB with a high estimate. That means with a localStorage cap of ~5MB for most browsers, there is very unlikely to be a real single puzzle that messes with localStorage. Right now if anything goes wrong with the cache write, all that really happens is that the caching doesn't happen

Final misc. thought: There isn't really a great way to give users an option to cache or not cache, since it seems that all of the persistent options available (e.g., yajilin styling) are encoded directly in URLs. That said, I don't believe penpa gives you this option either and that seems to work fine with almost exactly this implementation

@vercel
Copy link

vercel bot commented Nov 22, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
pzprjs Ready Ready Preview Nov 22, 2025 3:45am

@EliDoris EliDoris marked this pull request as ready for review November 22, 2025 03:47
@EliDoris
Copy link
Author

Another note that I forgot to mention:

Space in localStorage could be very considerably saved with the incorporation of a couple of libraries, but I could not figure out how to do that in ecma v5.

md5 would allow the keys to be hashed instead of raw, reducing them to 128 bits instead of a ton of URL characters (which I think are 8-bit encoded). This would be a gigantic saving for each key

lz-string would allow the URLs to be tremendously compressed, since they're VERY compressible (long runs of the same character, many repeated sequences)

@x-sheep x-sheep self-requested a review November 24, 2025 22:04
@EliDoris
Copy link
Author

Closing request here since I'm opening it on the robx fork isntead

@EliDoris EliDoris closed this Nov 25, 2025
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

Successfully merging this pull request may close these issues.

1 participant