-
-
Notifications
You must be signed in to change notification settings - Fork 375
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
Inline CSS with Critters Plugin #642
Conversation
Quick thing, I'd like the bundle.css to defer loaded since this is inlined anyways. WDYT? |
Unless I've missed something, both The default Critters setup uses |
Hmmm, how about we inline what critters give us and put bundle.css as That should make our first-paint super fast |
I think our first-paint is already super fast with default setting. Don't think we should be doing anything custom/beyond what Critters offers, as that's the point/goal of Critters, no? Either way, sounds like you may want the |
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.
LGTM 👍
Oh I just read:
This seems fine, if it is indeed moving it to the end. Please just check that we don't have double preload css tags with |
Also, tried this right now and running into: GoogleChromeLabs/critters#5 |
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.
Yes it does put duplicate preload tags with --preload for bundle.css
. So that should be avoided if this plugin is in by default.
Also I still get the Defer unused CSS
lighthouse error, so may be swap
is a better option
btw there should be an opt-out/opt-in flag for critters because based on your css critters is running into edge cases. cc: @developit, posted one such on the bug thread in critters |
I think I see what you're talking about. The The tag is removed with |
This has affect when the app grows e.g. material.preact.com preaload: swap works pretty perfect with just a few characters even for bigger sites.
Chrome throws a warning for this in console IIRC |
Gotcha. It warns if unused, but not on double preload tag. Feel free to change it to swap, I don't have any objections! I'll likely be away from desk for a few hours |
How about along with a opt-out flag? |
Personally I don't like opt-out flags, so I'd be hesitant. I also not sure why you'd need one? Arguably, if we're making something a default behavior I feel that we should stand behind it 100© Unlike the esm feature, there's no compatibility or support issues. |
Because I feel that it's not very stable, I made like 4-5 changes to the source code in my node_modules before I could get it to work |
@lukeed @developit should we be concerned about the fact that even after using preload(swap), latest lighthouse still complains about unused for the link tag and even the inlined css is being reported as extra css supplied e.g. https://www.webpagetest.org/lighthouse.php?test=180913_MG_dc5a8260f5c19115230143e77c18527d&run=1 |
Also, another use case of opt-out flag/question: if I use a case in July aren't they better at giving me my critical css rather than critters? |
If it's not stable, then: a) we shouldn't include it |
We should as it'll give us great perf boost for whomsoever it works
I'll wrap my finding in a PR to critters, but have no ETA on this.
Agreed, do you wanna do this? |
Oops, sorry, I meant that those were three possible choices; not to do all three 😅 I'd be totally stoked with inline-css as a default feature, but we need to be confident in it. If we're not, then it either can't be a default behavior or shouldn't be there at all |
+1, does an opt in flag sound like a decent approach now? |
We could do it like the esm stuff Opt in now and if we solve all the problems we can make it the default |
1e80b3b
to
8a999a9
Compare
added a flag, and conditional preload of css if critters is used |
packages/cli/lib/index.js
Outdated
@@ -31,7 +31,8 @@ prog | |||
.option('--analyze', 'Launch interactive Analyzer to inspect production bundle(s)') | |||
.option('--prerenderUrls', 'Path to pre-rendered routes config', 'prerender-urls.json') | |||
.option('-c, --config', 'Path to custom CLI config', 'preact.config.js') | |||
.option('--esm', '[EXPERIMENTAL] Builds ES-2015 bundles for your code.', false) | |||
.option('--esm', 'Builds ES-2015 bundles for your code.', false) | |||
.option('--critical-css', 'Adds critical cssto the prerendered markup.', true) |
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.
I would make this --inline
or --inline-css
, but maybe that's just me /shrug
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.
Nah that sounds better
@@ -10,8 +10,9 @@ | |||
<% if (htmlWebpackPlugin.options.manifest.theme_color) { %> | |||
<meta name="theme-color" content="<%= htmlWebpackPlugin.options.manifest.theme_color %>"> | |||
<% } %> | |||
<% const filesRegexp = options.criticalCss ? /\.(js)$/ : /\.(css|js)$/;%> |
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.
I don't understand – we'd still want to preload some CSS, especially the routes' chunks.
@prateekbh FYI - failing tests are now actually relevant to your changes |
It passes now but it shouldn't, I haven't fixed the preload tests don't know why they are passing |
fixed everything, good to merge. plz review |
Dismissing my own review as I added commits
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.
I can't approve since I initiated the PR 😆 Looks good!
now @developit also has a commit 😆 |
Critters issue should be fixed in 1.2.0. |
6c8c812
to
d50d68b
Compare
@ForsakenHarmony can you review this one :) |
@@ -10,8 +10,9 @@ | |||
<% if (htmlWebpackPlugin.options.manifest.theme_color) { %> | |||
<meta name="theme-color" content="<%= htmlWebpackPlugin.options.manifest.theme_color %>"> | |||
<% } %> | |||
<% const filesRegexp = htmlWebpackPlugin.options.inlineCss ? /\.(chunk\.\w{5}\.css|js)$/ : /\.(css|js)$/;%> |
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.
template.html
is already complicated and this adds more to it 🙈.
@developit any plans on making it similar to what CRA does?
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.
Well I can take a look at this in next iteration, but not for this PR
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.
LGTM
What kind of change does this PR introduce?
Feature
Did you add tests for your changes?
No
Summary
Uses Critters to inline critical CSS on the client bundle(s) for production and development.
The default settings are good 👌 but can be changed by end-user thru
preact.config.js
if/when needed.Closes #637
Does this PR introduce a breaking change?
No