Anki Forums

Exernal JavaScript file not working at first

Hello. This is a minor inconvenience, but I can’t figure out why Anki rejects any method from my external JS file AT FIRST on Desktop. What I mean :

  • in the editor, if I switch between the front and the back templates just once, it works just fine from there.
  • same when starting review : only the front of the very first card will show the error, but all the following cards with the same template work just fine. Even going back to the first card displays it properly.

The importing script is at the bottom of the editor and all script using methods from this file is written in another script tag lower.

Another bigger problem however is that JS doesn’t work at all on AnkiDroid with the imported file, but no error is shown, just the HTML.

Any idea of what’s happening ? Thank you in advance for your help.

The error :

Invalid HTML on card: ReferenceError: randomInt is not defined
ReferenceError: randomInt is not defined
at eval (eval at (, :3:16)
at eval ()
at Function.globalEval (
at Ha (
at n.fn.init.append (
at n.fn.init. (
at Y (
at n.fn.init.html (