-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Print stylesheet picked for "Reduce unused CSS" #13264
Comments
Thanks for the report! totally agree that we should not be flagging print stylesheets here. Unfortunately the CDT protocol does not tell us the
document.styleSheets for sheets with a truthy href (ignores internal styles) and media.mediaText . Ignoring the print sheets in CSSUsage is possible in this manner.
It get's tricky when you consider the more complex values for the media attribute. Example:
This is how it looks in I'd expect us to ignore this too. Also, we should ignore stylesheets like Of course we could parse the media attribute and do a bunch of shenanigans to determine applicability, but it is not trivial (see https://www.w3schools.com/tags/att_link_media.asp). Maybe we can look at the trace to determine if the stylesheets were loaded as render blocking requests (#2065 (comment)). Circumvents the complexity and uses what we care about directly: ignoring the CSS if reducing it wouldn't reduce the amount of render blocking bytes. |
Blocking render isn't the only downside, though. A low(est) priority stylesheet can still interfere with downloading other more important resources that are triggered or discovered after the download for the stylesheet has begun. IOW, the audit isn't just a measure of unused bytes; it attempts to only report on unused bytes that Lighthouse believes are competing with bytes that are used.
One big difference is that smashingmagazine has it at the bottom of their HTML. That reduces the likelihood of network contention with other resources declared in the page and is likely why it's not showing up in the report. |
Also FWIW the reports I get have "Reduce unused CSS" under Passed audits for your site. This run, for instance, does mention that all of the print style sheet could be saved because it isn't used, but doing so would only have saved something like 30ms of the overall load, so isn't worth bringing up and so it's placed under "Passed audits". I see the same thing in reports from web.dev/measure |
While we could specifically omit print stylesheets from this audit, it is still downloaded. So we think it's worthwhile to continue to flag. It's up to you if you want to take action on it. |
FAQ
URL
https://tv2.dk
What happened?
Taking the lighthouse test here or in Chrome, results in our print stylesheet being 'tagged' as unused CSS.
What did you expect?
As stylesheets with media="print" are considered non-renderblocking - and browsers are free to delay load of them untill needed - it seems wrong, that they are treated as "reducedable". Print-stylesheets should not impact performance, as I see it - but I might be wrong, though.
What have you tried?
Running the same test on https://www.smashingmagazine.com/ which also has a print-stylesheet doesn't give the same result - ie. the print css is excluded from the "Reduce unused CSS" results.
How were you running Lighthouse?
Chrome DevTools
Lighthouse Version
8.4.0
Chrome Version
95
Node Version
No response
OS
Mac
Relevant log output
No response
The text was updated successfully, but these errors were encountered: