npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

parallel-dom

v0.9.0

Published

pdom

Downloads

8,235

Readme

Parallel DOM npm version

Make your apps faster, parallelize away heavy DOM operations.

Usage

$ npm i parallel-dom

Javascript

Example | Demo

import PDom from 'parallel-dom';

const pdom = new PDom(
    // The root, the subtree will be 
    // made parallel.
    '#root', 

    // Javascript entry point of the script 
    // to run parallely inside the parallel subtree.
    () => import('path/to/script/which/runs/in/parallel') 
);
pdom.render();

React

Example | Demo

// parallel-component.tsx
const ParallelComponent = ({ prop1, onCallback }) => {
    // heavy operations.
    // ...
    return <button onClick={onCallback}>{prop1}</button>
}
import PDom from 'parallel-dom/react';

const ParallelComponent = PDom(() => import('./parallel-component'));

export const App = () => {
    const [p1, setP1] = useState('');
    return <>
        ...
        <ParallelComponent prop1={p1} onCallback={cb} />
    </>
}

React limitations

  1. Not supported: unserializable props (JSX in props etc.)
  2. Callbacks in Props are supported, but they are all async.

Under the hood

  1. Creates a dummy shell iframe on a subdomain.
  2. Passes the scriptUrl and creates a clone of the passed DOM element to the above frame.
  3. The iframe loads and runs the script.
  4. Since, iframe is cross origin, the browser creates a dedicated process for it.
  5. We use origin-agent-cluster header to enable multiple PDom to have their own dedicated subframe process.

For more details:

Supported Browsers

  • Chrome
  • Edge

Degrades to single threaded, on unsupported browsers.

Self hosted

You can host PDom on your own if you want to avoid using the pdom.dev domain for some reason.

Vercel

Quick deploy on Vercel.

Deploy with Vercel

Your own infrastructure

  1. git clone https://github.com/pdomdev/pdom
  2. cd pdom
  3. npm i
  4. npm run build
  5. Serve the dist folder with your own static server (like nginx). Or could use http-server.
  6. You could also do npm start to run a local developement server.

Domain and header configuration

  • Configure the web server to add the following response header (Already done in the above template for vercel):
Origin-Agent-Cluster: ?1
  • Configure a wildcard subdomain, with your DNS. Here is some documentation on how to do this with common Domain providers.

FAQ

  • What are you talking about ? iFrames suck!

iFrames were once insecure and often used for nefarious purposes. Browser makers have introduced many new security requirements as either defaults or even removed the older insecure ways entirely. The technology has advanced significantly. Some of the security features PDom uses to secure the iframes:

Sandboxing:

Sanboxed Iframes create a secure context 
with no access to the parent's context.
In browser script injection: 

Your javascript is never hosted on PDom server. 
Its injected at runtime by your parent application to the frame.
  • I don't trust a third party domain. Can I host this myself ?

Absolutely! The whole thing is open source, and we have included documentation on how to host this yourself. We have also built a Vercel template for you to quickly deploy the service if you use Vercel.

FWIW, you could use any static hosting provider, like github pages, netlify etc. As PDom does not really need a backend server, it's purely client.