-
Notifications
You must be signed in to change notification settings - Fork 384
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
Introduce stylesheet prioritization when determining which to concatenate #2346
Conversation
ab7a382
to
72b5a57
Compare
Awesome! Excited to see this. It'll help a lot when working with excessive CSS issues. |
c4c1b56
to
60e4e42
Compare
I'm not sure what to do about these two points:
There is an indication now but it is just an HTML comment, so it could still be disorienting to a user who expects the admin bar to be present. Otherwise, the way that a user could discover that the admin bar is being excluded by re-validating the URL via the compatibility tool: On Native mode in particular, they could decide to reject the validation error to cause the admin bar to appear, though with the warning as expected: This would not be advisable in Transitional mode because the rejected state would then cause the |
Build for testing: amp.zip (v1.2-alpha-20190519T052057Z-60e4e427) |
This is looking sharp! I am not too familiar with the sanitizers yet, especially the one for stylesheets. That's why I cannot give detailed feedback on the general approach and the todos you added. But after going through the code and testing it with a few themes, this seems to work as expected. Happy to give it a more thorough spin tomorrow though. Alternatively, I imagine that @kienstra might know this area better than I and could also provide some more valuable feedback? Correct me if I'm wrong 🙂
Agreed, let's take this step by step. |
Regarding:
Could we show a "watered down" admin bar? Something along the lines of an empty Admin bar with a placeholder text indicating the truncation. |
If we did this we'd still need to include the CSS for the admin bar, at least a subset of it. And the I was giving it some more thought last night about what do do and I'm thinking this: if the user is authenticated, we should skip I guess this is just re-hashing #1921. |
52131c9
to
1c5a639
Compare
Rebased with changes from |
1c5a639
to
ee9fbb5
Compare
Comment was related to "how to provide an indicator" that the admin bar is hidden. |
$priority = 70; | ||
} | ||
|
||
if ( 'print' === $node->getAttribute( 'media' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The media
attribute in <link>
element can be either a single media type, a white-space-separated list of media types, or a complex media query.
Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#Attributes
So this simple equality check might not be enough. Although the more complex media
declarations might not be very common, so perhaps it's not a big deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. In the case of a non-scalar media
then the stylesheet would just be handled as a screen
priority, which isn't the worst case. Since a simple media value is going to be the vast majority of cases, I don't think we need to worry about it here. But it's good to keep in mind.
@swissspidy The remaining todos in the description are not for tackling in this PR. |
What about the remaining todos in the code? |
There are three and they are largely for future reference, so they don't need (or can't be) done yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get this out for some testing 💥
Fixes #2322.
A theme's stylesheets should never be excluded in favor of the admin bar CSS. Similarly, print stylesheets should never be included at the expense of plugin stylesheets. This PR introduces prioritization when determining which stylesheets to include and which to exclude when the tree shaker is not able to reduce the total CSS to the 50KB limit. The changes here should result in a drastic reduction in the frequency of a theme appearing completely broken when viewing in Native/Transitional modes.
The stylesheet priorities are:
wp-includes
If it so happens that the Admin Bar CSS is excluded, then the HTML element for the admin bar as well as its associated CSS are both excluded.
Since the admin bar is automatically excluded, there is now no need for the option and it is removed:
TODO
Other items for follow-up