-
Notifications
You must be signed in to change notification settings - Fork 24
Need a section outlining limitations of current techniques #53
Comments
That's great! |
Thanks both. |
Hi, |
Yeah, I'll get a notification then |
Once we have some initial text, we should quickly translate it to "bikeshed" and start doing detailed review as a Pull Request. BikeShed's syntax is a bit of a burden of entry, so the quicker one of the folks editing the translate the incoming text, the better. |
I can get the text we come up with into a bikeshed document, but I might need a little help with Github PR stuff as we get going :D |
Sure, no problem. Happy to provide help with the PR stuff. Key is that we have a clean commit history and make sure we track who made the contributions. When sending the PRs, particularly for ones like this one, we need to make sure that the author of the text is captured correctly, so:
|
@andykirk When you are ready to submit text to be added, it seems I'll need some information for proper authorship attribution ➸ how would you like me to reference you? |
Thanks Tommy. Andy Kirk andy@andykirk.net |
Hi, Limitations of current techniquesThere is currently no native CSS mechanism available to developers that achieves the primary function of container queries, which is to employ the full capabilities of CSS to a specific element tree based on the state and properties of their container. Therefore developers must look to workarounds to achieve their goals. These workarounds and their limitations are outlined here: The use of Media Queries can only affect CSS changes based on the state and properties of the viewport. The viewport is not a good indicator of the state and properties of a particular container within the viewport. The use of CSS layout methods such as Flexbox and Grid, alongside CSS-based workarounds (such as the Fab Four technique) cannot employ the full capabilities of CSS on an element tree. The use of iframes produces the closest effect to what Container Queries is intended to achieve, but their use has two significant drawbacks:
JavaScript-based solutions (for example EQCSS) should not be considered an adequate replacement for a native CSS solution for all the same reasons any other layout- or appearance-based declarations are the domain of CSS, not JavaScript, and the usual caveats of JavaScript availability and failure still apply. |
This is an excellent overview @andykirk ! |
Thanks @jpamental |
@andykirk This is excellent. Thanks so much for writing this up! Out of curiosity, have you considered mentioning any performance drawbacks of JS-driven solutions? (I know @eeeps has done a little research into this.) I’m only asking because @marcoscaceres mentioned during the kickoff call that issues impacting end users are really compelling to implementers, and speed/performance seems like it could be a good one to hone in on. What do you think? |
Thanks @beep - no, actually I hadn't. It's not an area I'm strong in, tbh. |
@eeeps and I did some performance research on my container query script in ausi/cq-prolyfill#39. I can try to write something (short) up that describes the minimum performance costs of a javascript solution. |
@ausi Marvelous, thank you! Adding you as a co-assignee. |
Minimum Performance Cost of a Container Query Solution via JavaScriptOn first render:
After every subsequent render that affects the matching state of at least one container query:
Or shorter: The minimum performance cost of a JavaScript solution is about 6KB more render blocking JavaScript and a reflow after every significant layout. According to my research these should be the absolute minimum costs of any JavaScript solution (most scripts cost more performance-wise). The KB numbers are taken from the most popular scripts. Does this help so far, or should it me more detailed? |
I think that including @ausi 's addition is good, but I think that the stronger point is that layout is the domain of CSS, not JS (which is well known, and by design). So adding the 'and JS would be bad for performance too' should be a secondary reinforcing case. |
I fully agree. |
I'm curious about these numbers:
Is that 3kb for the gzipped plugin code? Are stylesheets included in that? And for 6kb are we saying the minimum size of a plugin for this is 6kb minified (but uncompressed)? I just tossed my most recent stylesheet loader and element query plugin into Closure Compiler and minified it and I get <2kb uncompressed, 764 bytes gzipped, and this wasn't written with the intention of being small. Should these numbers be adjusted downward, or better explain what they cover in their estimate? |
You make a good point @tomhodgins - I think that if we are going to include a performance consideration it's probably worth not talking specific numbers, but rather focus on the fact that it does require additional request, download, and processing resources as @ausi laid out above. Best to not get specific where not needed. |
Great point.
They are an average size of some general purpose container query scripts. There is no real minimum for the size because we didn’t specify the use cases yet and solutions can be very different.
I think you are right, we should probably remove these numbers. My intention was to note that the required scripts are huge in many cases How about this:
|
Strong agree! @ausi, I love your condensed list. Just me, but I think that’s the perfect level of detail for now. |
What's the impact per element to which the JS is then applied (and what's a typical number of element to which CQ would be applied)? Does the browser then need to recalculate styles once or for each? |
This is where the separation between ' virtual stylesheets' and 'events' makes a difference. In some plugins, all element queries are treated as a separate stylesheet, and all stylesheets are reprocessed upon each event (commonly Other stylesheet loaders register specific queries to events on specific elements in the document (either through browser events, or observers like Resize Observer or Mutation Observer). In this case, only those stylesheets tied to specific events on specific elements in the document would be repopulated. ReproCSS is like this. Lastly, it's possible to load event-driven virtual stylesheets on global events, or element-specific events, but only to repopulate the stylesheets if they are different than the current styles, which also saves repaints. My latest As for the number of elements affected by each element query - often it's one (the same being queried), sometimes it's a handful (the element plus some children), but rarely is it more than 5 different selectors in one query. EDIT: ^ those numbers are for selectors, not # of elements matching those selectors in the document. Often 1 selector matches 1 element in the document, but it can be multiple. That's why 'style scoping' or 'selector scoping' is important, so you don't have to use ID's or unique class names to target a matching element :D |
An optimized CQ script should not have a significant impact per element. And for determining the minimum performance cost we should assume an optimal JS implementation I think.
This can be anything from one single element up to thousands of elements.
This also depends on the actual JS implementation. But in the optimal case one recalc/reflow should be enough (even for thousands of elements). More recalcs/reflows might be needed if the CQ elements are nested, but this strongly depends on the actual use case.
Many CQ scripts don’t use “virtual stylesheets” at all, they just switch classes on and off (or custom attributes). In the case of “virtual stylesheets” CSS parsing would have to be added to the performance cost. But for the minimum cost this is not relevant I think. |
Iframes as Mini-ViewportsIframes allow you to 'modularize' some HTML by embedding it in an HTML document as another HTML document. This lets you use media queries for 'modular' styles in a way similar to writing container queries. There is at least one plugin that uses iframes to contain self-responsive 'modules' as part of a larger site layout. Pros
Cons
Element Queries are not Syntactic Sugar for Media QueriesThe most-used feature of media queries is the ability to set width-based breakpoints based on the browser's viewport. Most container queries are also based on an elements width. In non-dynamic layouts, where the width of 'modules' in the layout ultimately end up tied (even indirectly) to the viewport's width, it may be possible to predict or pre-render container queries and express the same styles as media queries. There is at least one plugin that can convert container queries to media queries. Pros
Cons
|
This is starting to take shape, so it would be good to start moving some of the above into a couple of pull requests (otherwise, we risk this becoming a mega thread). |
Hi, It would seem to me that we should be as concise as possible in order to make reading the doc as painless as as possible, and thus improve the chances of it being read and understood. Just my 2p. |
Let's find a balance between the two. @andykirk let's use yours as the base of the pull request, and then @tomhodgins et. al can layer any additional information on top, if necessary... we can then chop chop chop words as needed. |
Sounds great to me, @marcoscaceres. @andykirk (and/or @ausi), feel free to open a PR to tackle this! We can continue the discussion there. |
Great, happy to. I’ll think add @ausi’s JS parsing and nework bits to the JS section. Also, can I clarify; am I meant to be opening the PR on the bikeshed file? Sorry if that’s a dumb question. I haven’t used bikeshed before. |
Not a dumb question at all! but yes, on the BikeShed file. Don't worry too much about getting the syntax right at this point. That's what we have @tomhodgins for :) |
Great, thanks. |
Hi, |
@andykirk Oops, good catch! I’ll close this out. (Apologies for the oversight. I’m traveling this week, and prep for the trip has kept me away from the CQ work. I’ll be back on it next week.) Thanks again. |
Like this, but for Container Queries.
@andykirk, who wrote an excellent article outlining a bunch of use cases and current-workaround-techniques, has agreed to give this a go, soonish (I’ll assign him as soon as he accepts the collaborator invite).
The text was updated successfully, but these errors were encountered: