3 ms·
You can absolutely reuse a document fragment https://ibrahimtanyalcin.github.io/Cahir/ https://ibrahimtanyalcin.github.io/Cahir/ the whole rendering uses a si
by ibowankenobi 1y ago
You can absolutely reuse a document fragment
https://ibrahimtanyalcin.github.io/Cahir/ https://ibrahimtanyalcin.github.io/Cahir/
the whole rendering uses a single fragment.
- halapro 1y agoYou can absolutely not reuse a DocumentFragment. The moment you append it to a node, the fragment is emptied. https://dom.spec.whatwg.org/#mutation-algorithms https://dom.spec.whatwg.org/#mutation-algorithms > To insert a node into a parent before a child [...]: > If node is a DocumentFragment node: > Remove its children
- ibowankenobi 1y agoPeople have trransformed their brain because of using frameworks and do not understand how DOM works. I pasted A LIVE example to prove you wrong and you will still attach me whatwg link. YES , when you append it is emptied! Keep a reference to the same fragment and REAPPEND to it! REUSE it. If you want to empty without appending, call replaceChildren() since it inherits from Node. Why are people stubborn on things they dont know????
- spankalee 1y agoWe are only talking about the DOM and not about frameworks. DocumentFragments empty their contents when appended. This is standard DOM behavior. To "reuse" a DocumentFragments after appending it somewhere you have to repopulate it with _new_ DOM, which is no different from creating a new fragment. At that point are you really arguing that you can keep a container and keep refilling it and that counts as reuse in the sense we mean? Reuse in spirit is reusing the DOM in the container, not jus the empty container.