Message from JavaScript discussions
July 2017
— I already posted this at one point but I want some thoughts on it... this is SUPPOSEDLY the fastest way to parse HTML string into DOM nodes:
function newFragmentParse(sourceHtml) {
return document.createRange().createContextualFragment(sourceHtml);
};
A DocumentFragment is the natural choice as it is speedy, but what is that? createRange()
? Where does that exist in the DOM?
— What I worry is that it is referred to by something somewhere in the DOM, making my template engine leak memory
— ?
— Well, if, say someone wants to delete their engine instance, I want to make sure the cached DocumentFragments are also deleted
— I know about ranges from clipboard api
— I haven't used them before
— They're pretty easy to work with if I remember correctly
— Well, when creating a range like that, is it only returned or is there a range somewhere in the DOM?
— Furthermore does the range refer to the fragment?
— Hm, wait, maybe I am seeing it wrong. The range is returned I think.
— Ranges represent selections