magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.57k stars 9.32k forks source link

Critical CSS blocks interactivity, shows broken image, causes jank in Luma #28913

Open Leland opened 4 years ago

Leland commented 4 years ago

Preconditions (*)

Magento >2.3.4 Magento 2.4-develop

Steps to reproduce (*)

  1. With Luma active on Magento >2.3.4, enable Critical CSS: bin/magento config:set dev/css/use_css_critical_path 1

Expected result (*)

Actual result (*)

All told, here is what the default critical CSS experience on Magento 2.3.5's Luma looks like:

MicrosoftTeams-image (5)

Compare to the final loaded result:

image


Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

m2-assistant[bot] commented 4 years ago

Hi @Leland. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

Please, add a comment to assign the issue: @magento I am working on this


m2-assistant[bot] commented 3 years ago

Hi @engcom-Alfa. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Alfa commented 3 years ago

The issue is still reproducible on fresh 2.4-develop

Preconditions:

  1. Sample Data;
  2. Enabled Critical Path (bin/magento config:set dev/css/use_css_critical_path 1);

Manual testing scenario:

Go to Storefront -> Men category (for example);

Actual Result: :heavy_multiplication_x:

Screenshot from 2021-01-20 14-58-10

Compare to the final loaded result:

Screenshot from 2021-01-20 14-58-25

magento-engcom-team commented 3 years ago

:white_check_mark: Confirmed by @engcom-Alfa Thank you for verifying the issue. Based on the provided information internal tickets MC-40520 were created

Issue Available: @engcom-Alfa, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

mrtuvn commented 3 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 3 years ago

Hi @mrtuvn. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 3 years ago

Hi @mrtuvn, here is your Magento Instance: https://b059cf801e5e47fd4ebfc068b3d0179e-2-4-develop.instances.magento-community.engineering Admin access: https://b059cf801e5e47fd4ebfc068b3d0179e-2-4-develop.instances.magento-community.engineering/admin_fb68 Login: b451eebb Password: 1c9f51794a7b

Leland commented 3 years ago

Yes, there are other things that could be moved off the critical path. That doesn't mean that critical CSS is pointless though, and, besides, this issue is about the fact that the critical CSS in Luma is not good. This repo should have an example of a really well-made critical CSS file.

mrtuvn commented 3 years ago

Seem we need extra workaround with critical for magento luma. From the docs guide i see some approach with penthouse but I'm not sure which is correct way https://devdocs.magento.com/guides/v2.4/frontend-dev-guide/css-topics/css-critical-path.html (docs not write-well and not much information) Just wonder is there any correct way out there automatic generate css without manually approach

mrtuvn commented 3 years ago

I do not remember exactly what tool was used to create critical path css for Luma theme. Probably it was either https://www.npmjs.com/package/critical or https://www.npmjs.com/package/penthouse. Or even https://www.sitelocity.com/critical-path-css-generator But I remember that generated critical path needed to be refactored as well because of some layout problems in generated css.

Here is my infor related with this problem. Which mean css critical need extra effort workaround (not well-written). Probably we miss some styles critical at the point of view FE, need for early stage above the fold Now i realised why we don't have critical default for blank theme :) Leave it's responsibility for FE devs

Leland commented 3 years ago

For this issue, we could even handwrite some manual critical CSS just as an example.

In my org, we are using Penthouse to generate the critical CSS, however. It would be an awesome thing to create a Grunt task that handles this, though that's totally unnecessary to just close this issue!

ihor-sviziev commented 3 years ago

Please note that critical.css file probably should contain critical css both for mobile, tablet and desktop, otherwise it will be too jumpy during page load

roman-mer commented 3 years ago

For this issue, we could even handwrite some manual critical CSS just as an example.

In my org, we are using Penthouse to generate the critical CSS, however. It would be an awesome thing to create a Grunt task that handles this, though that's totally unnecessary to just close this issue!

Can you share your Penthouse setup in Magento 2?

Leland commented 3 years ago

@roman-mer sure - we're using Azure to handle deployments. We built a Penthouse node script that runs during the deployment that crawls through a headless Chrome instance and visits a specified number of URLs (homepage, PDP, etc). We then have some Regex that removes selectors that match to reduce the overall size. And finally, we have some manual CSS that is appended to it, which then produces a single critical.css file. It's very much in alpha state (and proprietary) so no code to share, sadly.

roman-mer commented 3 years ago

Someone might share a Penthouse setup in Grunt (Magento 2) I found such a customization recommendation, but so far I have not been able to implement it:

add new task grunt.initConfig({ penthouse: { extract : { outfile : '.tmp/out.css', css : './dist/css/full.css', url : 'http://localhost:9000', width : 1300, height : 900, skipErrors : false // this is the default }, }, });

mrtuvn commented 3 years ago

i think there are not common results for all here. You have to build with your own tools to meet your requirements Build process deploy like Leland describe above. Css will change not only by the page you visit but also the viewport related (width height). Height 200 will be difference with Height 900. You need hand-on at output generated file for some improvements Default luma critical would not much help for you since styles quite big with we have alot styles and merged to 2 files (styles-l, styles-m). Almost of them (90%) is not all you need for specific page

For improve performance overall in m2 not just need from css side but also need improve from js too

mrtuvn commented 3 years ago

@Leland Can you share how big size of your critical.css in your org? My site generate css critical file around ~ 300KB It's extremely big for single critical is it? My ideally it's should size around 20-30KB

Leland commented 3 years ago

@mrtuvn depends on the site. For this issue, I'd recommend staying in the 15-50kb range, however. Increasing every page's document size by 300kb will cause Luma's First Contentful Paint time to increase significantly.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

Leland commented 3 years ago

This is a confirmed issue, and should not ever be marked stale IMO… perhaps stale bot’s settings should be tweaked?

mrtuvn commented 3 years ago

Hi @Leland https://github.com/magento/magento2/pull/33084/files we already have PR for such case @ihor-sviziev should we add exempt labels also for confirmed

ihor-sviziev commented 3 years ago

@mrtuvn let's discuss it with other maintainers