Javascript imports

I’m currently on AnkiDroid 2.22.3

Some time (1 year?) ago you used to be able to place the javascript for a card into a common file and import it using a script element:

<script src="_common.js"/>

This was very useful where you have a large number of cards using the same javascript functions (eg. event handlers), as there was then only 1 place that had to be changed to update all of the cards.

This import no longer works and it appears to me that the javascript has to be embedded directly into the card inside of a script element.

Is it possible to reinstate being able to import a common javascript file?

Have you put the file in collection.media? I’m not aware of import functionality getting removed here (and it was working until recently for other people: Is there a way to not show file import failure messages?).

Also, do you see any error message?

Yes it’s in the collection.media.

It used to work some time ago, but now the debugging console shows an error that the event handler function contained in the file is not found.

There is no 404 re not finding the file.

Is it only the new reviewer or the old one too?

I’m only using the old one.

So, sounds like the file is succesfully imported but the code then crashes, in which case the problem is in the javascript of your _common.js file. If you you could post the content of the file and the exact error you see in console, then the solution may become apparent (unless it’s a minified bundle of a couple thousand lines of JS…)

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.