text
stringlengths
0
1.36k
**Mikeal Rogers:** I don't agree that it's anti-web, but I will say that the recurring theme here is that this thing that is standardized and adopted is just more important than this thing with feature X. That's a recurring theme that we'll see in technology forever. The thing that everybody happens to be using, the th...
**Alex Sexton:** I think that is the direct reason why websites are really slow on mobile devices today. Node is the reason. The fact that synchronous, giant builds \[laughter\] -- no, seriously... The fact that synchronous, giant builds became the quick standard of just like "Take everything in your Node modules and b...
**Mikeal Rogers:** I thought Alex Sexton was my co-host, not Alex Russell. \[laughs\]
**Alex Sexton:** That's the problem. So if we would have started with something that could do asynchronous loading, then I think we'd be in a much better place, where people would only be loading things that they needed for any given page... By default, because that's how it works.
**Mikeal Rogers:** I actually think it's very valuable to not have to write a lot of your own code, and whoever is the best at creating reusable code and dependency networks that allow you to do a lot more while writing a lot less are gonna win. And eventually, that's gonna turn into a bigger bundle, and it doesn't rea...
**Alex Sexton:** No, I mean... By default, if you asynchronously loaded packages, you could just say -- like, nothing has to change, it's just when you hit this page, the new package loads. It's a built-in kind of feature to the asynchronicity of the thing. Right now there's some cool stuff with like async/await on top...
**John-David Dalton:** It's already making its way into build tools, too. Webpack now supports dynamic import syntax, and it should do that - deliver part of the bundle upfront and then part as needed.
**Mikeal Rogers:** \[40:06\] I don't know, I'm so much skeptical of our ability to cut up the application code this much to make a big difference for secondary and third loads, when if you have a service worker, it gets loaded after the first load anyway, and if you have a mechanism by which you can update it before th...
**Alex Sexton:** There are definitely parts of the solution to this problem, but you can never get around the fact that the first time that you go to a web page, it takes 10 seconds on a not brand new iPhone to parse the JavaScript. It's a real problem and it's not going away. I think out current build system is a dire...
**Mikeal Rogers:** I don't agree with that at all, but okay. \[laughs\] At some point we have to move on though. Alright... So Alex Russell is gonna take a break, and then we're gonna get Alex Sexton back for a minute. \[laughs\] When we come back, we can get into the project of the week.
**Break:** \[41:29\]
**Mikeal Rogers:** Let's now dig into the project of the week. JD, you wrote a loader to -- I believe this is too to the universal spec, that you do your working on?
**John-David Dalton:** Yes, so it's part of Lodash 5... So the Lodash 5 is the thing I'm working on. It's going to be ES6+ only, and I did not want to have to transpile it back for Node 4 or 5 or whatever, so I wanted there to be a loader for that, and so I had to create one. I've created a work in progress - this has ...
It is for Node 4+, it supports .js, .mjs, it supports dynamic imports, it supports the file protocol, it supports live bindings, it's going to be spec-compliant by default, which means that things like unambiguous grammar are off by default, but you can opt into them... Things like carrying over some of the CommonJS go...
\[44:30\] What's nice about that is that you can just ship one version of your code and it just works. The consumers of your package don't have to care about it either. They don't have to worry about if they're loading ESM or CommonJS. For them, things will just work. So it removes the compile step, it removes having t...
**Mikeal Rogers:** I've really gotta ask you, so the usage here is -- basically you do require @std/esm, and then the import syntax in the language starts to work properly... How the hell did you do that? I'm looking at this going "How would this ever work?!"
**John-David Dalton:** So I need to add an example for common usage - what you would normally do is inside your package you have an index.js. Your index.js can be basically two lines long. The first line is to require the standard ESM loader, the second line is to then require your ESM code; usually module.exports=requ...
What we do is we tie into Node module compiling and loading mechanism, and we can then parse the code, transpile it on the fly, cache it and then load it. But the thing is because we're dealing with such a small subset of the language, we can do this in microseconds, so not even milliseconds - superfast. It's cached, s...
What we've been able to do is most of the time whenever you have a loader that you're overriding, it's a global change, but that would be not good, because you would have modules that all of a sudden start working that did not opt into it... So I've done a lot of work to ensure that only packages that are using the sta...
I've also done it in a way to where you can support versions of the ESM loader. So one package could be using version 1, one package could be using version 2, and they're not gonna conflict or stomp on each other.
**Mikeal Rogers:** That's impressive. That's really hard to do properly.
**John-David Dalton:** Yeah, so we've got that going... The idea is that, again, the consumer should not have to worry about it; it's just a way for you as a package author to have your import/export with a very little ceremony. You basically require it as a dependency, and then you have that small hook inside your ind...
\[47:57\] Again, I like unambiguous module grammar; I don't necessarily want all my code to be .mjs. I like a lot of the Node carryover stuff, so for me, I'll be configuring it with those options. But for everyone else, it will be standards, and as spec-compliant as possible by default... Which is great, because if it'...
**Mikeal Rogers:** And to make Alex here very happy, it means that you can just use this in the browser without any tooling and without Node, right? Eventually, when we have \[unintelligible 00:48:48.24\]
**John-David Dalton:** So ESM and Node will still have Node's module resolution - lookup, I believe...
**Mikeal Rogers:** Oh, right, right.
**John-David Dalton:** So that doesn't transfer over to the browser. I wish it did, because that's super handy, but --
**Alex Sexton:** It could with a loader override, I assume...
**John-David Dalton:** That is correct, you are right. But the good thing is that existing tools should continue to work. So this is something that you can opt into, it gives you enhanced support...
Another thing I like is that with Node v7+ it's like 99.9% ES6-compliant, right? It's just essentially missing tail call and import/export. So this import loader, this ESM loader just adds that import/export bit to the language, so it's not having to support a ton of crazy stuff, and that's why it can also be super fas...
One of the first things I did was reach out to one of the Acorn devs to see if they could come up with a way to do a fast top-level parse, and sure enough they were able to cook one up in like a day and a half. I then took that to a project called Reify, which is done by Ben Newman, and Reify is what my loader is based...
**Alex Sexton:** That's it?
**John-David Dalton:** For me? Yes. \[laughter\] It was four months for me, but Ben has been working on this project for over a year, so I'm leveraging the work and the experience -- a project that has not only been worked on for a year, but it's being used by MeteorJS right now in production... So it gives me confiden...
**Alex Sexton:** Sure.
**John-David Dalton:** To me, it's super simple - it's one function call, then after that you get it. What's nice is, as you see based on the readme, it works in the Node REPL too, which is where you just require it and then all of a sudden the syntax just works, import/export after that, which is super handy. I dig th...
One of the things I'm excited about that's non-standard is the support of gzipped modules. You know the browser supports gzipped compression for your resources - JavaScript, CSS, HTML... It seamlessly handles that; Node doesn't seamlessly handle loading those kinds of resources. Node has gzip support built in, but ther...
\[52:33\] Lodash 5 will be gzipped and will be less than 90 kb on disk, so I've optimized it heavily there. One of the secret sauces to that is loading gzipped files seamlessly. To the end user, their code will just work, but instead of it loading a .js file, it's loading a .js.jz or .mjs.jz file.
**Mikeal Rogers:** Word of caution, though - not everybody should do that, because if you have a lot of tiny gzip files, they end up being really large, actually... Like, there's not a huge amount of benefit to that. And I imagine uncompressing it in real time can be kind of slow, as well.
**John-David Dalton:** Actually, if you gzipped -- so I didn't experiment where I just gzipped my Node modules folder, Babel... You know. After a while, your build tools and your build change - you'll have over a gb inside your Node modules folder... So I gzipped it and I saved 500 mb out of the gate. And it turns out ...
Isaac of npm (formally Node) has also written a 3x faster gzip loader, which is what I'm also using. It's super fast. I'll be using it, like I said, for Lodash. I like that, because with Lodash, if you wanna load the kitchen sink, it's 600+ modules; I'm using that as my benchmark for the ESM loader as well, seeing how ...
I will say it's not a silver bullet, but for me, since most people have multiple versions of Lodash, 4 mb x 4 mb + 4 mb starts to add up, and eat into people's quotas for things like Azure functions or AWS Lambdas, or Electron apps and things like that. Your Node modules folder tends to inflate and can have consequence...
**Mikeal Rogers:** That's a really good point.
**John-David Dalton:** \[unintelligible 00:54:50.08\] the actual ESM loader. What this doesn't show is that the ESM loader will be a zero dependency package, and will be under 30 or under 40 kb. So the ESM loader is not only small, but zero dependency as well. I wanted people to be able to feel like they can add this t...
Lodash will be taking a dependency on it - I'm incorporating feedback from people like Sindre Sorhus because he's massive in the ecosystem, so I want him on board with the ESM loader as well, the naming...
**Alex Sexton:** Is that based on his tweet that said "I will never move to .mjs in the history of \[unintelligible 00:55:58.03\]"
**John-David Dalton:** I had been discussing this with him before that even. If you noticed in his tweet, he says he might use the loader that I'm working on, so he's been in the loop for a while.
**Alex Sexton:** Oh, nice.
**John-David Dalton:** \[56:11\] Even the name... One of the first things I did was look up a standard, official-looking name, and get the namespace for that and the package for that. It's because I wanted to feel official, I wanted to be spec-compliant, I want to be easy to reach for and use, and that would be a user ...
**Mikeal Rogers:** Corban in the chat is asking (just general) "What's the SSD and CPU on what you're doing these benchmarks on?"
**John-David Dalton:** Good question. I have the MacBook Pro (Touch Bar) laptop plugged in. Even unplugged, I get similar speeds unless I'm on low battery, and that's when the CPU starts to kick in. I will say that it varies from project to project, but the cost to me isn't egregious and in some cases it's a benefit. S...
**Alex Sexton:** What are people's concern there? They're just on like a resource-constrained device, like a Raspberry Pi, or something?