-
Notifications
You must be signed in to change notification settings - Fork 385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement transformer in optimizer for media, sizes, and heights #4439
Comments
See ampproject/amphtml#27468 for validator to allow |
Unless I totally misunderstand, this does not make sense as to how CSS works. The
Just moving the media attribute into CSS provides us with a condition under which to do something, but we still have to define what that do something actually means. I would assume we'd want to hide the element when the media query is matched. The question then is how to best hide it so that:
I'll experiment with a simple |
Given that |
Using
The question now is what a meaningful specificity would be here to ensure that something like a Or would it be preferable to use multiple ways of hiding the image at the same time ( @westonruter, @sebastianbenz thoughts? |
Could we simply negate the media query?
Disclaimer: I'm not a CSS expert so there might be cases I'm missing. |
You are too humble. I didn't know you could negate media queries in this way 😄 But apparently the syntax is like so: @media not all and ($EXISTING_MEDIA_QUERY) {
display: none;
} Reasoning by Simon Sapin at https://www.quirksmode.org/blog/archives/2012/11/what_the_hells.html#c15586:
|
Thanks for working out the correct syntax! @schlessera would it be possible for you to port back the test cases for the new attributes to AMP Optimizer? |
@sebastianbenz Yes, sure. The test cases only will create a failing PR, though... |
Hmm, after the negation, the actual page does not work anymore. Both versions of an image are shown, instead of only the one that matches the media query. The media query doesn't seem to do anything in that form. Some more investigation needed... |
The negated media query itself seems to work as expected: https://codepen.io/schlessera/pen/dyoryPx It must be the generated HTML/CSS the optimizer produces, then... |
It seems to be the double parentheses around the media query, when it already had parentheses to start with. So, this works: It seems that there can't ever be two levels of parentheses, the logic has to be done with I think we should be good with just not adding parentheses here, but I have to admit I'm not a CSS expert either. So, we'd have the following changes.
That still looks correct to me... |
Well, that would have been too easy, right? The following does not work:
So, I'll change the logic now to check whether the trimmed value starts with a parenthesis. If yes, assume we start with a feature and prepend In the above case, that would then produce:
Hopefully that will be correct enough. Next step would be writing a full media query parser, I'm afraid... |
..and here we go down the rabbit hole... What about I extracted a list of valid media queries from the official test suite. This is probably a good start to check whether we cover all features. |
From looking at the valid media queries and the spec, it seems that support for an existing I'll add a check for that. |
Okay, I went another route. Using the spec and your test data, I built a regex: https://regex101.com/r/Xctler/1 This looks like it might handle all the cases (at least the ones we know of), and it adds semantic knowledge about the individual building blocks. The logic can then act on these building blocks, instead of doing arbitrary string manipulations. |
Ah, the test data does not take comma-separated media queries into account. Because of the specific behavior of the So, the following query:
would be computed in the following way (not acting on the entire thing):
|
Feature description
Currently SSR is blocked when an AMP page contains AMP components that make use of the attributes
sizes
,heights
, ormedia
. While the AMP Optimizer does not currently implement a transformer for this, there is a transformation which can be made as noted in Future Work of Server-side rendering for AMP caches:Note that
media
can be transformed just by moving the attribute into a CSS rule. This involved ensuring that the element has an ID to target in a selector.Related #4213
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation brief
QA testing instructions
Demo
Changelog entry
The text was updated successfully, but these errors were encountered: