by smusamashah · 2y ago · 0 comments
I am not a web developer, and always find NPM etc way too much for my occasional needs.
When I search internet for anything, 90% of the times I get an NPM based library that can not work in browser with just a <script src="lib.js">.
JavaScript has improved a lot and does not really need Node/compilation steps for almost all my use cases. Is there anything where I can search for browser only, client side javascript libs?
Usually this will give you a .min.js file ready for you to script include on your site, for example, unpkg.com/mithril
Sometimes library authors don't default the export to a browser ready minified version or ESM module, in which case, you can snoop around the built package at unpkg.com/browse/mithril/.
Most READMEs worth a damn should tell you how to use their libraries without npm if possible. Unfortunately, a lot of library authors suck.
The nerve of them not catering to the small percentage of use cases for a project they often do in their free time and often for free. The entitlement is real.
The closest service is https://esm.sh, but you can’t download from it.
https://esm.sh/ is definitely a good option too if you're OK with modules.
The reality is that only frameworks and very popular browser-specific packages do that.
Some things still won't work because they rely on some server side library, like loading files or something, but you won't want those for web development anyway. You might also find that some libraries don't handle being included as a script very well, but you can instead use the import statement and that will probably work better - use <script type="module"> and inside that use import something from "<whatever the unpkg URL is>".
For production usage this isn't ideal because you're not as in control of the code you're depending on, it's less reliable, and it's more requests than if you just bundled everything together, but not everything needs to be for production usage!
There used to be bower, thankfully that’s now gone.
> JavaScript has improved a lot
So has its ecosystem. Setting up parcel or Vite is straightforward and should get you out of those problems. The time when you could just download a .js file and stick it in your vendors folder is long long gone. Please bundle and minify your files before serving them.