HACKER Q&A
📣 schwartzworld

What if browsers included common JavaScript packages?


Like it or not, the cat's out of the bag on JavaScript. Lots of the websites we use every day rely on a small number of JavaScript libraries. How many different times do you think your computer and phone have had to download the entirety of React, Vue and jQuery? I've had this idea in my head for a while that browsers should have these libraries included, allowing developers to just import them without the user having to download anything but the actual application code.

`import React from "@browserIncludedReact/v16.9";`

It might feel weird to build this into the browser, but unless you browse with JS turned off, you are downloading these libraries several times a day, if not hundreds. Non-tech people usually leave js on, so the savings, while small for each person, could end up being huge on a macro scale. Curious what people's thoughts are?

Curious what people's thoughts would be?


  👤 beardyw Accepted Answer ✓
I seem to remember that happened with JSON, but I assume it is now low level code.

Since service workers are now commonplace, it would be more helpful to somehow share the caching of commonly used libraries, so once downloaded in one place the browser would let it serve for another. Not sure how it could work, but would need to ensure the libs were identical. Maybe by use of a hash? Mmm ..


👤 theandrewbailey
Browsers are big enough already without having several versions of several libraries packaged in. It won't help when a new version or an entirely new library is released.

Further, we tried this 15 years ago with popular CDNs serving these libraries, but we discovered that having multiple sites sharing the same one raised several security concerns.


👤 dave4420
This would make it harder for new frameworks to get adopted, because they would always have the disadvantage of being an extra download for the browser.

If you think we can’t improve on React/Angular/Vue then great, but for everyone else it’s a disadvantage.