5 ms·
If you don't need to support older browsers, just write raw JS and use module imports. This means that you're pulling down a lot of different files instead of o
by kerkeslager 7y ago
If you don't need to support older browsers, just write raw JS and use module imports. This means that you're pulling down a lot of different files instead of one big blob, but a lot of those files will already be cached in the user's browser from CDNs anyway.
Yes, you don't get JSX this way, but I've always seen people's obsession with syntactic sugar as bikeshedding. Typing out code isn't the bottleneck for development, it's just one of the easiest things to optimize, so people obsess over optimizing syntax while much more significant problems like debugging and traceability are largely ignored because people don't understand them as well. Worrying about losing the benefits of JSX when you're writing a language that still fails silently when you reference a mis-spelled property on an object is like worrying about your haircut while you bleed out from an arterial wound.
- cogman10 7y agoBrowser support is fairly new, I was actually surprised when you mentioned you could do this now :). But yeah, probably not a terrible way to go. If you are working with an http2 server today then this will work really well.
- fzzzy 7y agoChrome, Safari and Edge have supported it since late 2017; Firefox since May 2018. So it should be quite safe to use by now.
- kaoD 7y ago> a lot of those files will already be cached in the user's browser from CDNs anyway Not anymore. https://www.jefftk.com/p/shared-cache-is-going-away https://www.jefftk.com/p/shared-cache-is-going-away
- kerkeslager 7y agoInteresting. That means that the module approach isn't faster than bundling, but with HTTP2, the module approach shouldn't be slower than bundling.
- kaoD 7y agoBundling also deletes dead code so it can potentially save a lot, especially if you import huge libraries and only use a small part of them.
- kerkeslager 7y agoA much better solution is to not import huge libraries you will only use a small part of.
- z3t4 7y agoCan you give an example of a bundler that removes dead code and not just minifies it? Dead code removal in JS is a bit tricky, unless we are only talking about code after return statements and other low hanging fruit.
- kaoD 7y agoIIRC as long as you use ES modules, tree-shaking is trivial? EDIT: not that trivial https://webpack.js.org/guides/tree-shaking/ https://webpack.js.org/guides/tree-shaking/
- z3t4 7y agoHmm. Now that we have async functions meybe we could also add the pure keyword in order to help optimizations.