# Javascript needs "forcing" on latest Linux desktop version

**URL:** <https://forums.ankiweb.net/t/javascript-needs-forcing-on-latest-linux-desktop-version/11087>\
**Category:** Help\
**Created:** [June 27, 2021, 10:37pm UTC](https://forums.ankiweb.net/t/javascript-needs-forcing-on-latest-linux-desktop-version/11087 "2021-06-27T22:37:04Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![kleinerpirat](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/kleinerpirat/32/19863_2.png) [@kleinerpirat](https://forums.ankiweb.net/u/kleinerpirat)\
**Post date:** [June 28, 2021, 9:47am UTC](https://forums.ankiweb.net/t/javascript-needs-forcing-on-latest-linux-desktop-version/11087/2 "2021-06-28T09:47:51Z")

</div>

You’ll need to adjust your scripts, as Anki ~~\>=2.1.41~~ will not reload the entire page, but only the parts that change (for performance reasons).

> [@\[regression?\] javascript issue with let and const variable assignation](https://forums.ankiweb.net/t/regression-javascript-issue-with-let-and-const-variable-assignation/10715/2):
>
> I guess this is because Anki uses a single webview for the review session and just changes parts of it for each card (recycling the webview periodically). You have to manually execute your code for each card, maybe relying on hooks to trigger it, depending on what your code is trying to do.

> [@Editing Anki CSS/html](https://forums.ankiweb.net/t/editing-anki-css-html/7480/3):
>
> Anki does not rebuild the DOM for efficiency purposes. Having to reload MathJax, jQuery libraries, etc. on every single card is pretty wasteful. In the future AnkiDroid will also probably head that way.  
> A strategy to avoid running code too many times is “guards”, where you have a variable, which checks, whether a specific code was already run:
> 
> ```auto
> // globally
> if (!globalThis.myCodeIntialized) {
> // run my code
> globalThis.myCodeInitialized = true;
> }
> 
> // or for specific HTML elements
> if (!htmlElement.hasAttribute("has-myCode")) {
> // setup htmlElement
> htmlElement.setAttribute("has-myCode", "");
> }
> 
> ```

Normal function calls like `fooBar()` within your template should execute with each new card, but if you want to make sure:

> [@\[regression?\] javascript issue with let and const variable assignation](https://forums.ankiweb.net/t/regression-javascript-issue-with-let-and-const-variable-assignation/10715/5):
>
> Best practice would be to move your code into an [IIFE](https://developer.mozilla.org/en-US/docs/Glossary/IIFE).

---

_[View the full topic](https://forums.ankiweb.net/t/javascript-needs-forcing-on-latest-linux-desktop-version/11087)._
