r/programming • • Sep 25 '20

Modern JavaScript Explained For Dinosaurs

https://medium.com/the-node-js-collection/modern-javascript-explained-for-dinosaurs-f695e9747b70
749 Upvotes

167 comments sorted by

View all comments

21

u/palordrolap Sep 25 '20

TL;DR In browser-JS can't load dependencies from the server on the fly without severe problems, and if you don't have access or don't want the inconvenience of putting loads of <script src="etc." /> into your HTML <head> and then keeping them up-to-date as your project changes, the solution is ... simple [?] [citation needed]:

Use something that crunches all your JavaScript (and third party dependencies) into one giant JS file and use one unchanging <script src/> in the HTML!

Advantages:

  • No more HTML management hell!

  • Since the JS is being preprocessed, technically it can be anything that can be converted into JS rather than just plain JS.

  • Shiny! Scalable! Cross-platform! Cutting edge! Bingo-bango-buzzwords!

Disadvantages:

  • The management hell is now in the JS.

  • There are numerous competing systems for doing the aforementioned crunching, and this changes all the time. You may need to learn many of these.

  • All need a command line to work. Better get comfortable with that.*

  • There are numerous competing languages that can be turned into JS by these systems, including other versions of JS that may or may not have the features you're using by default. You may need to learn many of these.

  • If you are a dinosaur you will miss the old days. (*Although a surprising number of dinosaurs are comfortable with a command line).

5

u/therearesomewhocallm Sep 25 '20

More Disadvantages:

  • Your website takes 30s to load because it waits on one giant JS file when most of it could be loaded on demand.

  • The JS file is large enough that a browser cannot compile-time optimise it.

  • Any webworkers are either inlined (hooray for eval) or run 10x slower.

5

u/zephyy Sep 25 '20 edited Sep 25 '20

Your website takes 30s to load because it waits on one giant JS file when most of it could be loaded on demand.

what is code splitting?

The JS file is large enough that a browser cannot compile-time optimise it.

split & minified JS should never have this problem.

6

u/dnew Sep 25 '20

I am amused that your link loads as a web page and then immediately erases itself on my browser.

1

u/zephyy Sep 25 '20

my b, it included the extra URL query string stuff that google adds for highlighting text

1

u/dnew Sep 25 '20

Ah, cool. Yeah, I hate that Google does that.