4 ms·
If this works, why don't browsers do this natively?
by Joeri 11y ago
If this works, why don't browsers do this natively?
- dorianm 11y agoBecause it would not be backward compatible, eg: el.style.color = "red" // write console.log(el.style.color) // read el.style.color = "green" // write console.log(el.style.color) // read Outputs: "red" then "green". Batched: it outputs "green" then "green".
- coderdude 11y agoThere could be a flag included in the HTTP response header (X-Batch-DOM) or a meta tag like <meta http-equiv="X-Batch-DOM" content="1">. The response header would be a better place for that flag since you can stick a meta tag at any point in your markup (even where it's incorrect to do so). The browser could choose to ignore the meta tag if any JS has executed or it could reload the page with the setting turned on. Not ideal. Anyway, if you feel completely sure that your code would not do anything like you've demonstrated then batching might work fine. Though this basically excludes the safe use of externally linked scripts that you can't control (analytics is one example).
- Symen 11y agoBy reading the README I guess that exceptions would be an issue. With fastdom they are thrown asynchronously, so a different API is required to catch them.