As we consider swinging back towards URL based package management* I think it's important to reflect on why we moved away from CDN and <script src> in the first place

🧵 (a short thread)

*see Deno's package management
There were 3 main issues (IMO) with just hot-linking all your dependencies from a CDN.

1. We didn't have JS modules
2. We didn't have imports
3. We didn't have HTTP/2 (or it wasn't the standard)

This caused some issues. What were those issues? Great question!
1. Because we didn't have JS modules & imports, the libraries we loaded attached themselves to the global scope (window.jQuery). This is less than ideal for 2 reasons: Dependencies aren't explicitly loaded, and 2) any other dependency you run could mutate a library you rely on.
2a. We also had trouble loading our dependencies in order. See, in the good* old days, we would just load all of our dependencies in order (think waterfall) synchronously.

Example:
<script src=" http://cdn.com/jquery ">
<script src=" http://cdn.com/jquery-plugin ">

*but kinda bad
2b. But then we started loading JS deps asynchronously, which had performance benefits, but it meant that you couldn't always depend on dep #1 loading before dep #2.

This is when libraries like RequireJS and LoadJS popped up to help us load our dependencies asynchronously.
2c. Then eventually we got bundlers like Webpack, which allow us to "import" a JS module into another module, and it takes care of all of the magic behind the scenes to make sure our modules are loaded and run in an order that doesn't break*

*at least not too often
3. The last reason, tho I'm sure there are more, is because we didn't yet have HTTP/2, we wanted to load a single JS file, and a single CSS file, because our servers/browsers weren't equipped to serve/load multiple files at once.
But now, the landscape has changed:
- We have imports + modules in JS (as of ES2015)
- Imports + modules are starting to work in browsers ( https://caniuse.com/#search=module  says ~90%)
- HTTP/2 is the standard (HTTP/3 may be around the corner?)
Now, more than ever, it totally makes sense to reassess whether it's time to reinvent, or at least adjust, the way we install, manage, transpile, and bundle (or not!) our first-party, and third-party dependencies.

(end of thread)
You can follow @JakeDohm.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: