-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
[Audit] Avoid CSS @import #11863
Comments
Thanks for filing @andydavies I think this is a great idea! This could even be an opportunity with quantified savings estimates using our graphs. Are there any situations you can think of where |
@andydavies did you start prototyping out an implementation on this? IMO, preventing imports is totally legit. We've just been ignoring this because we thought @import was not used heavily. I guess you've seen it enough times to warrant some action, eh? |
@paulirish Yes, I've got a prototype up and running just need to clean it up so I can make a PR for review but bee na bit busy with the day job ATM I've gone for the approach of using the PageDendencyGraph rather than searching code for Comment from the top of my audit says
|
Still see CSS imports more frequently than I'd like even on 'modern sites' e.g. snowpack.dev had one until a few months ago https://www.webpagetest.org/result/201202_DiS7_f3b2bb222f6532ba74ad8fc22866c413/1/details/#waterfall_view_step1, https://stanford.edu has a few, and a search of publicwww turns up plenty. |
nice. yeah we think that's probably the smarter.. just gotta deal with some cases where there's
Awesome. Appreciate the extra evidence.
all good, not rushing you... just didnt want to step on your toes. looking forward to the blog posts on the 3p work you've been doing! :) |
Is this audit on all @import statements, or just @import statements used in external stylesheets? @import used in inline Context I'm working on the CSS Cascade Layers feature, which currently relies on We are working on introducing a similar syntax to |
Just @import referenced from external stylesheets
On the @imports in HTML it's probably worth checking the Blink quoting
issues mentioned here are / get fixed
https://csswizardry.com/2018/11/css-and-network-performance/
…On Tue, 17 Aug 2021 at 21:08, Xiaocheng Hu ***@***.***> wrote:
Is this audit on all @import <https://github.com/import> statements, or
just @import <https://github.com/import> statements used in external
stylesheets?
@import <https://github.com/import> used in inline <style> elements can
be discovered as early as a <link rel=stylesheet>, and shouldn't affect
loading performance. So there's no need to discourage it.
------------------------------
*Context*
I'm working on the CSS Cascade Layers
<https://groups.google.com/a/chromium.org/g/blink-dev/c/chiJ2GIECPc/m/sIF9pfsdAAAJ>
feature, which currently relies on @import to assign external/3P style to
a cascade layer. The syntax is @import url(...) layer(my-layer).
We are working on introducing a similar syntax to <link rel=stylesheet>
<w3c/csswg-drafts#5853>, but right now ***@***.***
url(...) layer(my-layer)</style> is the only valid syntax to achieve the
purpose.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#11863 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADIILFD6R52FIGMA7TKEX3T5K6VVANCNFSM4VEKC26Q>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
|
Provide a basic description of the audit
Check whether stylesheets are being imported from within other stylesheets.
Aim is to identify the imported stylesheets through the request chain.
Drawback to this approach is that only identifies cases where the stylesheet is imported in the Lighthouse run. Searching stylesheets source code is an alternative approach that works for a wider set of scenarios e.g.
@import
enclosed within a media query. This second approach would still miss some stylesheets e.g those wrapped in IE's conditional comments.How would the audit appear in the report?
This audit will come under performance.
When passing:
When failing:
How is this audit different from existing ones?
There's no existing audit.
Imported stylesheets are visible in the Avoid Chaining Critical Requests audit but they're not highlighted and there's no specific advice about avoiding them.
What % of developers/pages will this impact?
Querying https://publicwww.com for
"@import url" filetype:css
returns over 100,000 CSS files using@import
.How is the new audit making a better web for end users?
Styles imported into another stylesheet via
@import
delay initial rendering as they are discovered late – a browser must download and parse the outer stylesheet before they are discovered.Gains will depend on the number and size of imported stylesheets, and the length of the import chain.
As example of the gains that might be made here's a comparison of snowpack.dev with and without the imported stylesheet on Moto G4 / 3G.
In the top test the @imported stylesheet has been blocked and the page starts rendering 0.5s earlier.
https://www.webpagetest.org/video/compare.php?tests=201221_DiWH_925d14973580957e917ef244fb6f322a%2C201221_Di7P_cec2262fdef423f979661401f762199f&thumbSize=200&ival=100&end=visual
If the imported stylesheet was directly in the document the gains should be roughly similar as the preloader will discover it and dispatch the request earlier (avoiding the latency penalty)
What is the resourcing situation?
@andydavies will implement and document the audit
Any other links or documentation that we should check out?
None
The text was updated successfully, but these errors were encountered: