LinkeDOM focuses on being fast and implementing features useful for server side rendering. It may allow you to do things that are invalid DOM operations. and jsdom focus on correctness. While currently deno-dom is slower than LinkeDOM in some cases, both are significantly faster than jsdom, so if you require correctness or features not related to server side rendering, consider deno-dom.
While LinkeDOM works under the Deno CLI, it does not type check. While the
provided types work well when using an editor like VSCode, attempting to
strictly type check them, like Deno does by default, at runtime, it will fail.
This is the same if you were to use to type check the code. The maintainer
has indicated they aren’t interested in
. This
means for Deno, you need to use the --no-check=remote
to avoid diagnostics
stopping the execution of your programme.
This example will take a test string and parse it as HTML and generate a DOM structure based on it. It will then query that DOM structure, picking out the first heading it encounters and print out the text content of that heading:
Alternative API
For the can be better suited for certain SSR workloads. This is
similar to jsdom’s JSDOM()
function, in the sense it gives you a “sandbox” of
a scope you can use to access API’s outside of the scope of the
document
. For example:
const { document, customElements, HTMLElement } = parseHTML();
customElements.define( “custom-element”, class extends HTMLElement { connectedCallback() { console.log(“it works 🥳”); } }, );
document.toString(); // the string of the document, ready to send to a client ```