3 ms·
The module system in nodejs is far superior as it lets you treat modules like variables, pass them around etc. The root of all complexity is that different code
by z3t4 9y ago
The module system in nodejs is far superior as it lets you treat modules like variables, pass them around etc. The root of all complexity is that different code parts entangles. With local requre's all code parts can truly separate which makes it easy reuse and delete code. And you don't have to hunt a function/variable across the whole code base to figure out where and what it's used for.
And it also lazy loads the module. ES6 modules might be a 44 years old standard, but NodeJS modules are better !
For use on the web the web server could grep require from the source and push modules to the browser, so when a module is required it will be loaded from cache. The browser could even pre-parse the module to speed up run-time for when it's required.
- tzahola 9y ago>For use on the web the web server could grep require from the source and push modules to the browser Nope. The server can’t figure out which modules are needed unless it runs the program: if (isPrime(366226717)) { require(“hugeModule”) }
- z3t4 9y agoNo need to make sense of the code, just run a regex to find all require's. Could also use a package.json
- kofejnik 9y agocan you regex this: var _0xdde4=["\x6C\x65\x66\x74\x70\x61\x64"];require(_0xdde4[0])
- z3t4 9y agoworst case scenario is that the browser has to request it from the server. This is bad because the execution would have to stop and wait, but for most cases it would just be for a few milliseconds. And the developer should take that into account and maybe prep the cache for possible paths.
- tzahola 9y agorequire(calculateTenthMersennePrime().toString() + “.js”)
- deleted 9y ago[deleted]
- jakelazaroff 9y agoThe fact that they can't be statically analyzed is a huge downside. It's a trade-off.