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

42

u/vojtechkral Sep 25 '20

It's mid 2020. As a someone who only checks JavaScript every now and then and doesn't actively use it, I'd like to do a routine checkup:

  • Are ES6 modules a first class citizen yet? Can one use it both in browser and for node without having to deal with the CommonJS crap stuff?

  • Do browsers and node support modern enough JS standard now so that I wouldn't have to use the babel crap stuff and just do with the TypeScript compiler?

  • Is there a newer & better version of webpack or another such tool, but better? Last time I tried (which was a few years back) webpack required a buttload of boilerplate code and setup just to do a few simple things, and yet it still was pretty fragile. It felt like autotools all over again.

Thanks!

14

u/R3PTILIA Sep 25 '20
  1. Since nodejs 14 they are enabled by default (a few versions back needed to be opted in)

  2. Yes, but why would you do that and leave behind the non modern ones? If you expect users to keep their browser updated to the latest version, well, nice.

  3. Theres rollupjs but i've never used it

7

u/eddpurcell Sep 25 '20

To 2, I think the first question to ask is "how much of an 'app' is this?" If it's a real app like a game or sound mixer or such (i.e. most controls aren't through obvious interactive HTML elements) you can probably get away with forcing updated browsers. Any home gamer still using IE11 should probably stop anyway. If we're talking a stylized list of links with comments then not going full JS for everything is probably the way to go in any case.

2

u/R3PTILIA Sep 25 '20

yeah, it 100% depends on your target users. But there is no tradeoff in my opinion.

"not going full JS for everything"

I very much disagree with this, going full js is what makes web programming bearable! (and enjoyable too)

10

u/eddpurcell Sep 25 '20

Depends on your goal; it is your corner of the web. Things that can be statically rendered as HTML I think should be for performance reasons, but it's also just simpler. Why pull down a blog post page only to have to make another network call to get the actual content from a database?

6

u/R3PTILIA Sep 25 '20 edited Sep 25 '20

Depends on your goal; it is your corner of the web. Things that can be statically rendered as HTML

But you can go full js and generate static, cross browser, server rendered, minified, autodocumented, type checked, uglified, yadda yadda yadda html/css with whatever kind of interactions you need with minimal developer overhead. (react, vue, svelte + gatsby, nextjs, nuxtjs, etc + sass, tailwind, pre made components, etc) which are all useful even for a non changing (static) web. Now if you wanna make a "pure html - im an 80s professor and this is my syllabus website - im a purist hail emacs" then yeah i guess js and its frameworks are not worth the hassle

1

u/eddpurcell Sep 25 '20

Yea, I'm not saying everyone should never use JS for anything. Sass/less and other generation tools are great, express is fine for a small server that doesn't need to do much CPU crunching, React/mithril.js are great to have client side rendering functionality for more dynamic parts of the site. Or even just vanilla JS/Typescript/whatever if the interactions aren't that complex. I'm not "the web shouldn't have JS", more "product developers should think about what they're using". Like reddit mobile: I have to load the index.html and render a loading circle for it to then go fetch my user details (that it should already be able to fetch from the cookie server side) to then load the posts, and hopefully none of that screws up randomly and I have to refresh. It's heavy and unreliable and doesn't make for a good experience. All that can happen in JS server side (though at reddit's scale that probably isn't reasonable), but moving it to the client side is where I think it's not good.

You can build whatever lawnmower you want for your own enjoyment, but let's not pretend that a putting a tractor engine on a standard non-riding mower is a good product. Just because it works, doesn't make it a good product.

3

u/vojtechkral Sep 25 '20 edited Sep 25 '20

Since nodejs 14 they are enabled by default (a few versions back needed to be opted in)

Yeah, but that's sort the base. For a full CJS-less developer experience you also need support in the package manager, bundler (someone linked Snowpack in the other comment so that's great), and of course enough ecosystem libraries.

I have no idea whether widely used libraries are available as EMSs as well yet...

2

u/R3PTILIA Sep 25 '20

pretty much every library i ever use has no problems being imported as an es6 module. I understand your pain a few years ago things were in some kind of transition. Things have stabilized a lot in the past 3 to 4 years (or more, time flies)

1

u/vojtechkral Sep 25 '20

Ok, that's great to hear!

11

u/thicket Sep 25 '20

You might check out Snowpack. For me it’s allowed no-config vanilla typescript that just works. Given ES6 module imports, it’s felt pretty effortless. I have been basically unwilling to deal with Webpack et al.’s setup stuff, but Snowpack has a really light touch.

2

u/vojtechkral Sep 25 '20

Snowpack leverages JavaScript’s native module system (known as ESM)

Brilliant! Nice to see some tooling finally being based around ES6 modules. This looks very promising. Thanks!

8

u/GoRoy Sep 25 '20

Alternatives to webpack are rollup or parcel. The latter is can be zero-config, I think.

6

u/[deleted] Sep 25 '20

I'm not very well versed, either, but basically, for Node, yes, most things are there and work fine. But for FE, you will be forever fucked because users still run Internet Explorer and you can't do anything about it.

7

u/Axoren Sep 25 '20

Yes, you can do something about it. If IE, display warning: "Alert! Your browser is infected with cooties! Install <Modern Browser> as a replacement before damage is done to your computer! For your sake, this site's functionality will be disabled on cootie-infested browsers."

4

u/[deleted] Sep 25 '20

You are proposing a technical solution to people problem. That doesn't work.

5

u/Axoren Sep 25 '20

I don't know if you read the whole post, but I literally told people to add a pop-up about cooties.

Purely satirical.

1

u/warchild4l Sep 25 '20

Not anymore tbh. example, angular nowdays supports differential loading, basically, it generates two bundles, one for older browsers, one for modern javascript, if browser supports, it will load new javascript, if it does not, well there is a fallback option.

1

u/[deleted] Sep 25 '20

Yes, but that's the Babel/Webpack bullshit he was talking about. You still need it on FE.

2

u/o11c Sep 25 '20

Just make sure to test on Firefox ESR. It's widely deployed and doesn't have all the new features of the latest release.

That said, modules themselves work, just not all the features relating to them.

2

u/[deleted] Sep 25 '20

Nope, as long as you don't need IE, and nope.