My local js program is lagging, which part is causing it?

I am writing a Typeracer game and my longer texts are generating a lot of lag the further you get in the text (reload for random text). I am not entirely sure what is causing it however, which is why I am here to ask for your advice. The JavaScript file runs entirely locally (path: easteregg/secret.js). What part of my code is causing this much lag, and how could I fix/improve it?

Thanks in advance!

While I read the code, what’s a Typeracer game?

One thing that jumps out to me is your running a complicated script on every keypress (eventListener, input). Is there a way to perhaps rewrite this in .then syntax instead of a bunch of try catch blocks?

If you could show us some of your code maybe we can help more :slight_smile:

You can click the project in the post to go to the project page. From there you can click “View Source” to see the code. This js file’s path is /easteregg/secret.js

I didn’t experience any lag when I tested it out:


And considering I had to google the ALT code for ë and I am English, I think I did quite well
4 Likes