Let’s learn how unpkg the service and the open source project can improve performance for your company’s apps.
FYI: Before I get into the newsletter today I just want to mention that I’ll be on a family vacation all week and I don’t think I’ll even have access (let alone the inclination) to the internet. 🤠
A few years ago, Michael Jackson had an idea. He needed an easy way to make demos for his open source projects (specifically react-router) and realized that he already hosts all his projects somewhere: npm! So he could just setup a little node server that would act as a proxy to the files that are on npm. And here we are, almost 9 BILLION downloads per month later.
For example, to get d3 on your page, you could add a script tag like so:
You could also do:
Because unpkg redirects those to the above URL (in this case it’s because d3’s
package.json has a
unpkg field to point to that file specifically). It’s recommended that you specify a version though because otherwise user’s will start downloading the latest version which could break your application if there’s a major version bump:
That’s right, a version range works in there as well. Cool right?
unpkg is great for open source project demos and instructional material (I use it heavily in my Beginner’s Guide to ReactJS), but it’s not well suited for mission-critical applications at scale because:
> unpkg is a free, best-effort service and cannot provide any uptime or support guarantees.
That’s why Michael recommends:
> if you rely on it to serve files that are crucial to your business, you should probably pay for a host with well-supported infrastructure and uptime guarantees.
This is something that I plan on doing at PayPal eventually and I’ll tell you why. Most projects at PayPal are using much of the same technology. Most are using some version of react and react-dom, some are using rxjs, many are using lodash. Each of these projects serves its own
bundle.js file(s) that include these dependencies. So as users navigate around PayPal they’re re-downloading much of the same code just in a different form. Some companies enforce the entire company use the same version of some dependencies to avoid this problem. I think this comes with more problems than the solution merits
This is why I’m really interested in building a hosted version of unpkg at PayPal. Doing this will allow teams to use whatever version of whatever dependencies they like. If two teams happen to be using the same version of React (pretty likely), then the user wont have to download that version of react more than once. This compounds across the number of teams and projects PayPal has. And because I also write and maintain paypal-scripts, I can build-in a really nice process into paypal-scripts so people can get this functionality out of the box. Automatic user experience improvement! Woo!
I have a lot of things on my plate, but I’m hoping to be able to do this in the next few months. I think it’ll be a real win for people using PayPal products. Can’t wait to see those bundle sizes getting smaller! Good luck friends!
P.S. One other thing that I really love about unpkg is the index page for a package. Simply add a
/ at the end of the URL and you’ll see an index of the files as well as a version chooser which is pretty awesome:
Looking for a job? Looking for a developer? Check out my job board: kcd.im/jobs
Things to not miss:
Some tweets from this last week:
> It’s so nice to have technology recommendations that I know people will be happy with. Specific examples that come to mind at the moment: > React > Jest (and react-testing-library) > Cypress (and cypress-testing-library) – 24 Jul 2018
> I just found out that @codesandboxapp uses the first open source project I ever built 😍 > geniejs 🧞♂️ > > https://github.com/CompuIves/codesandbox-client/blob/a911927458058fa3ca10a84b0f41066f8f3a84b0/packages/app/src/app/pages/Sandbox/QuickActions/index.js#L4 … > > (and a recent one too in the same file! 🏎️)