5 ms·
If you look at why the bundles are so big, the frameworks are so large etc., you’ll realise it all comes down to fighting browser deficiencies: - no declarativ
by dmitriid 7y ago
If you look at why the bundles are so big, the frameworks are so large etc., you’ll realise it all comes down to fighting browser deficiencies:
- no declarative APIs for DOM updates
- no good APIs to do batch updates
- no native DOM diffing (so decisions on what to re-render have to be done in userland)
- no DOM lifecycle methods and hooks (you want to animate something before it’s removed from DOM, good luck)
- no built-in message queueing
- no built-in push and pull database/key-value store with sensible APIs (something akin to Datascript)
- no built-in observables and/or streaming
- no standard library to speak of
- no complex multi-layered layout which matters for things like animations (when animating a div doesn’t screw up the whole layout for the entire app/page)
etc. etc. etc.
As a result every single page/app has to carry around the whole world just to be barely useable.
- pier25 7y agoI agree that the browser has many deficiencies for the modern front end developer, but OTOH there is no real need to make huge bundles. As an example look at Svelte. It compiles down to super efficient imperative code without sacrificing the dev experience. A hello world weights like 5kB gzipped I believe.
- fhennig 7y agoI just had a look at svelte, and from the perspective of someone who isn't really a web developer, I think this is a the proper way to do it. All of the other frameworks seems so convoluted and to me it looks like people are reinventing the wheel left and right.
- M4v3R 7y agoActually, the minimal Hello world example in Svelte is 2.7 kB even before gzip. It's really awesome and I already used it in one production app, the results were pretty amazing performance wise.
- snek 7y agoThese things are being slowly worked on: https://github.com/WICG/display-locking https://github.com/WICG/display-locking https://github.com/tc39/proposal-javascript-standard-library/ https://github.com/tc39/proposal-javascript-standard-library... (https://developers.google.com/web/updates/2019/03/kv-storage https://developers.google.com/web/updates/2019/03/kv-storage) https://github.com/tc39/proposal-observable https://github.com/tc39/proposal-observable ...etc
- pier25 7y ago"Slowly" is the key word here. How long have they been debating the Observable proposal? 4-5 years?
- hajile 7y agoI thought Observable was dropped completely. It seems mostly unnecessary give that a Proxy can do the same thing (and much more).
- minitech 7y agoProxies and Observables are unrelated. Maybe you’re thinking of Object.observe?
- pier25 7y agohttps://tc39.es/proposal-observable/ https://tc39.es/proposal-observable/ It's (still) on Stage 1: https://github.com/tc39/proposals/blob/master/stage-1-proposals.md https://github.com/tc39/proposals/blob/master/stage-1-propos...
- hajile 7y agoYou are correct. I was thinking of Object.observe which was preached as the next big thing in JS only to finally be pulled from Chrome (around version 50 IIRC). That said, does a native observable actually buy that much performance-wise? If not, then perhaps an addon library is better. Once a library makes it into JS, it is there forever. That's a big risk when decent libraries already exist.
- worble 7y ago> As a result every single page/app has to carry around the whole world just to be barely useable. So pages before this javascript bloat became commonly accepted were unusable? Maybe at some point web developers have to accept that the web was simply not built for the things they're trying to do with it, and that comes with a cost. Maybe they should evaluating whether they _really_ need animations on everything, whether everything _has_ to be a SPA made in [current popular framework]. I'm not even saying these things are bad, they absolutely do have value, but that value has a tradeoff, and usually that tradeoff is placed on your customers.
- derefr 7y agoThe parent’s point is that, if all these things were browser JS runtime features, there’d be no tradeoff to be made. They’d be “free.” If every JS page in the world today includes the same line of code, isn’t it obviously the fault of browser makers for not making that line of code part of the JS prelude and thereby making it “free”?
- worble 7y agoThat's fine, and if they do end up being part of the JS runtime, then great! But right now they don't, so by including those you are actively having to pay the cost of doing so. My point of contention with the parent post is that these features are requirements for a webpage "to be barely useable". You can absolutely make great websites and webpages without these.
- moltar 7y agoThat’s a slippery slope. We’ll eventually turn the browser into an OS. And more features = more surface area for bugs.
- kalleboo 7y agoIt's increasingly looking like our two options are either 1. Turning the browser into an OS (what Google is working toward) 2. Downloading an OS on each page load (What webassembly is working toward)
- pas 7y agoBesides what snek mentioned the whole CSS Houdini effort is about providing better, finer grained tools to be able to do/control partial updates. That directly of course doesn't help with bundle sizes, but it means bundles don't have to carry so much logic and optimizations because they can just use the already performant APIs.
- makecheck 7y agoNote that you don’t really have to “animate something before it’s removed from the DOM”. A “disappearing” animation is an embellishment and a purely visual effect; therefore, it only depends on what the original object looked like, not the entire original object itself. It is a lot simpler to reason about the state of your system if you delete items immediately and create proxies to handle special effects for deletion. For example, to have an element “animate away”: create a new purely-visual element at an absolute location that looks like the original object, delete the original object immediately, and then let the proxy go away whenever it is done animating. This completely frees you from having to worry about the true lifetime of the original object.
- untog 7y ago> For example, to have an element “animate away”: create a new purely-visual element at an absolute location that looks like the original object, delete the original object immediately, and then let the proxy go away whenever it is done animating. This completely frees you from having to worry about the true lifetime of the original object. The OPs point is that doing this is far more DOM-intensive, and leads to worse performance. It isn't a good solution.
- dmitriid 7y ago> For example, to have an element “animate away”: create a new purely-visual element at an absolute location that looks like the original object, delete the original object immediately, and then let the proxy go away whenever it is done animating. This completely frees you from having to worry about the true lifetime of the original object. Yeah, and to properly do that you need that very same JS bloat to: - somehow observe a DOM element being destroyed (there are no lifecycle methods on DOM objects) - somehow figure out if it's the object being destroyed, or it's parent, or grandparent, or... - somehow quickly create a visual proxy instead of the object being destroyed, quickly substitute it in the DOM (avoiding repaints, reflows and jank). With all the correct things for it: size, position, scroll position, all internal representation (let's say we're animating a login form floding in on itself) - somehow animate that proxy object - and then remove that proxy object. It's a lot simpler By the way. If I remember correctly, just getting the position of an object causes a full-page reflow [1] [1] https://gist.github.com/paulirish/5d52fb081b3570c81e3a https://gist.github.com/paulirish/5d52fb081b3570c81e3a