What forces layout/reflow in Chrome
gist.github.com
gist.github.com
var w = element.clientWidth;
var h = element.clientHeight;
Is that 2 reflows or 1? var w1 = element1.clientWidth;
var h1 = element1.clientHeight;
var w2 = element2.clientWidth;
var h2 = element2.clientHeight;
Is this 4 reflows, 2, or 1?---
reading this article (https://developers.google.com/web/fundamentals/performance/r...) it sounds like it's 0 reflows if nothing has changed. In other words it's all cached
This'd be 2:
element.textContent = 'omg';
var w = element.clientWidth;
elem.classList.add('ok');
var h = element.clientHeight; var heights = lotsOfElements.map(function(el){
el.classList.add('ok');
return el.clientHeight;
});
Better is to batch the DOM updates and reads, where you can: lotsOfElements.forEach(function(el){
el.classList.add('ok');
});
var heights = lotsOfElements.map(function(el){
return el.clientHeight;
});Establishing containers as layout roots (generally fixed height/width and overflow:hidden) will constrain these sorts of costs.
This would be more interesting if it wasn't specific to Chrome only, but looked at the web at large. Maybe specs/things like this could be extended to be part of the standard instead?
When something breaks in Firefox, Safari, Vivaldi, Edge or other browsers (because obviously it was never tested outside Chrome) their answer is usually "Just use Chrome".
This is now not only happening at amateur-hour shows and quick Github POCs, but also at official products from big names like Google.
Basically "This website best viewed in Chrome". Haven't we already been there? We saw how that worked out, didn't we?
That sort of attitude is not healthy for the web at large, and documents like this will (IMO) further entrench that attitude, rather than the opposite.
But like I said, there are plenty of amateur-hour gigs following your play-book.
You decide which group you want to identify with. For me part, I know which I represent.
And thus for a small rant:
On a side note, I love how web-developers these days have the nerve to tell people how hard their job is because they have to support several browsers. Cry me a river. Nobody's job has ever been easier than yours.
Do you have to deal with messages not getting through in a message pump when threads are involved? Do you have to deal with how GPU accelerated graphics frameworks magically sometimes not showing windows when run in a Citrix TS, but with faulty Intel GPU drivers on the server? Have you ever tried to figure out why your code isn't getting the correct registry-entries, which you can see is there in a mixed 32-64 registry mess? Why that setting a configured was never shell-expanded, causing your script to break 3 layers in? Have you ever tried to debug why the file you just released a handle for is still locked, by yourself? Etc etc. These things a million times every day.
Web-developers have it so easy peasy as no other programmer in the history of programmers. I'll admit that's an opinion, but I'm pretty sure it closer to a fact.
Signed someone who has delivered cross-platform products, on-premise software across several versions and decades, with demands that nothing should ever be broken no matter what.
That's not my decision to make as it impacts production costs. The person paying the bills should be the one that makes the decision and my job is to inform him of the probable costs and provide statistics so he can measure the cost vs benefit for his intended audience.
This kind of crab mentality of "you aren't a real developer until you are miserable like me" is really getting old and it only serves to make the whole industry look standoffish and bad.
Yes, some of the work I do on the web is easy, but so is the view components of any other system. The time spent bit twiddling to try and get a little more performance out of a browser to be able to render a game at 60 FPS or spending time understanding what each browser compiles my JS to under the hood (after it was "transpiled" [i hate that word] from another JS dialect) so that I can figure out why what should be a simple copy is taking so fucking long is just as difficult as some of the shit you have to deal with.
Stop trying to make it into a contest.
Browsers are making my day to day work miserable. I wish O could target a reference css3 platform and browser specific bugs be damned.
I'm a web developer and, in my 11 years of doing this, the only people I've ever seen do that are those experimenting with a new feature that only works in Chrome or rank amateurs.
Knowledgeable web developers write code to standards, not browsers.
Changing your User agent also allowed you to use both in Firefox.
Details on why Inbox wasn't available at first are available in this thread: https://news.ycombinator.com/item?id=8606879
Really? I certainly don't try and work out how the spec says the document should render — I trust if browsers interoperably render the document the same, that's what the spec says. And I'm not someone scared of specs, having contributed to them for years and worked on browsers for years.
You're saying the same thing I am, Geoffrey. Sort of. I expect browsers to render the same way as the spec says it should. I then verify in each browser. When they don't, I adjust, but I never write code, only test in ... Opera ..., and expect it to be identical everywhere. I don't only read the ... Opera ... blogs and specs and expect it all to work the same all the time.
Users are running browsers, not standards. Writing to standards only works once the standard is widely distributed and implemented.
http://gent.ilcore.com/2011/03/how-not-to-trigger-layout-in-...
They look basically the same to me - this part of a browser layout engine hasn't changed much, and probably isn't likely to unless Chrome goes all GPU-rendering. And it includes Webkit browsers as well, so it's also Safari, mobile Safari, Opera, and Android Browser.
Thx for linking up Tony's post btw!
tldr: you can "fade in" a new element only if you trigger a reflow at the right moment
Even if the APIs in question require synchronous reflows now because they return some data, it may be possible to introduce new APIs that receive the data in a callback. (The usefulness of these APIs depends on the engine having support for off main thread layout, of course.)
Random aside: Dart's DOM originally offered these properties only as async but developers were unhappy with the ergonomics so Dart ended up delivering the sync APIs. :/