Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do single reflow #119

Merged
merged 2 commits into from Jun 8, 2016
Merged

Do single reflow #119

merged 2 commits into from Jun 8, 2016

Conversation

ghost
Copy link

@ghost ghost commented Jun 2, 2016

No description provided.

@ghost
Copy link
Author

ghost commented Jun 2, 2016

https://gist.github.com/lukasz-zak/48486ab35f7ea4bc1ba4 for speed reference

document.createElement() vs. document.createDocumentFragment()
If you are writing an application/page that does a large amount of DOM manipulation, using document.createDocumentFragment() can dramatically increase performance of your application/page. Per David Walsh, a senior web developer with Mozilla:
DocumentFragments allow developers to place child elements onto an arbitrary node-like parent, allowing for node-like interactions without a true root node. Doing so allows developers to produce structure without doing so within the visible DOM -- an increase of speed is the true advantage.
DOM injections and modifications are taxing, so the fewer the interactions the better; that's where the DocumentFragment comes in... Using DocumentFragments is faster than repeated single DOM node injection and allows developers to perform DOM node operations (like adding events) on new elements instead of mass-injection via innerHTML.
Conceptually, both work in a similar fashion, but as Walsh points out, createDocumentFragment is more like a virtual DOM, which you can modify without the cost of restyling/redrawing a page. You do all of the same manipulation as with createElement, but you just append everything to the DOM in one fell swoop, as opposed to many appendChild calls.

@kpdecker kpdecker merged commit 23cb886 into kpdecker:master Jun 8, 2016
@kpdecker
Copy link
Owner

Released in 3.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant