Hacker News new | past | comments | ask | show | jobs | submit login

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.




The fact that they can't be statically analyzed is a huge downside. It's a trade-off.


>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”)
    }


No need to make sense of the code, just run a regex to find all require's. Could also use a package.json


   require(calculateTenthMersennePrime().toString() + “.js”)


can you regex this:

var _0xdde4=["\x6C\x65\x66\x74\x70\x61\x64"];require(_0xdde4[0])


worst 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: