Yet another post about javascript persistence.
My suggestion is to make the javascript behaviour safer. The current persistence of the whole document object between can create incredibly juicy bugs like this: Issue with shortcut for a button
I only realized what the cause could be because I’d struggled with getting stuff working the same between desktop and Ankidroid and had to think a lot about the persistence problem.
Compromise for safety and consistency
Due to this latest bug I’ve come to think that actually the AnkiDroid way of resetting the whole document object would actually be preferable.
Pros:
- Consistent behaviour between desktop and mobile
- Less bizarre bugs in people’s javascript
Cons:
- Loss of the ability to load big js modules only once per review session, making javascript-heavy cards load faster on desktop.
- Lots of people’s current card templates using some front to back persistence breaking ← This is probably the big reason why doing this is would be bad
So…
In an ideal JS world…
Then some day, if possible, I’d like to have a separate storage of javascript objects (not just strings) which would allow loading large js modules once per review session instead of needing to load them on every card render.
Maybe a card template includes two document instances that are merged on card render? One is kept separate and persistent between reviews while the other is reset per card front / back. The merge would allow the card to access objects in the persistent one.