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?
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?
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