I live in a web world which is probably very outdated now in terms of whats available. The projects i work with are asp.net core with individual js and css files - bundled up in to files which are common throughout the pages (page navigation code/layouts for example) and separated for individual page requirements. But where 3rd party libraries are loaded separately (jquery for example).
I'm brand new to node.js, and although i likely don't fully grasp the concept, i'm really failing to understand the benefits of one - bundling all dependencies in to a single file.
My scenario:
I have multiple typescript files, most common, but at least 1 unique file used for a page specific purpose. Almost every page uses the JQuery library.
So in my page specific (and common files) i import jquery
import * as $ from "jquery";
The output of my typescript file is using the "CommonJS" module. So it outputs it as
var $ = require("jquery");
But because the browser doesn't understand "require" - i use a bundler to convert this .js file in to a file which contains the full jquery library within it (i'm currently playing with browserify and webpack).
All this so far i understand the need for. But what i'm failing to grasp is if i have 100 pages, all with a different function (and so all have their own typescript file and entry point) - meaning they all individually need to be bundled up with the JQuery library.
How is this in any way more efficient than just calling a single jquery library file for all the pages, which is cached and reused? Putting the whole JQuery library in to every single bundle.js file thats loaded surely can't be better?
My main goal is to use typescript files and a package manager like npm to allow me to easily manage and update my javascript packages (rather than the old way of copying the dist in to a folder and them slowly getting out of date). And although being able to "import" any package easily in to typescript is beneficial, it seems like a step back in progress that all my libraries are being downloaded 100's of times.
Am i misusing node.js? Or are there alternative ways to using typescript with external libraries without having to bundle everything up?
Thanks for reading.