Skip to content

Improve performance: reduce repeated DOM queries & heavy listeners#187

Merged
omroy07 merged 1 commit into
omroy07:mainfrom
Aditya8369:169
Jul 6, 2026
Merged

Improve performance: reduce repeated DOM queries & heavy listeners#187
omroy07 merged 1 commit into
omroy07:mainfrom
Aditya8369:169

Conversation

@Aditya8369

Copy link
Copy Markdown
Contributor

Changes Made
DocumentFragment Batching: Instead of appending each option button individually directly into the DOM (which triggers multiple reflows/rerenders), I modified the loadQuestion function in all the quiz JavaScript files to first append the options into a DocumentFragment. The complete fragment is then appended to the options container at the very end in a single operation.

Event Delegation: I removed the per-element onclick listeners being attached in the .forEach loop. Instead, I attached a single event listener to the parent #options container inside the DOMContentLoaded block. This leverages event bubbling (event delegation) to capture clicks on any child option button. This significantly reduces the memory overhead of having multiple listeners repeatedly added and removed when cycling through questions.

closes #169

@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown

@Aditya8369 is attempting to deploy a commit to the Om Roy's projects Team on Vercel.

A member of the Team first needs to authorize it.

@omroy07 omroy07 merged commit d7f77c2 into omroy07:main Jul 6, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve performance: reduce repeated DOM queries & heavy listeners

2 participants