Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Document CSS critical path #4726

Merged
merged 13 commits into from
Jul 30, 2019

Conversation

adifucan
Copy link
Contributor

@adifucan adifucan commented Jun 11, 2019

Purpose of this pull request

Document new feature CSS critical path for Magento 2.3 & Magento 2.2.
New CSS critical path feature is introduced for developers. Now they can eliminate render-blocking CSS resources with minified critical.css inlined in .
By using CSS critical path we deliver minified critical CSS inline in html and defer all non-critical styles that are loaded asynchronously. Thus we can significantly improve the time to first render of our pages.

This pull request (PR) ...

Affected DevDocs pages

  • guides/v2.3/frontend-dev-guide/css-topics/css-critical-path.md
  • guides/v2.3/frontend-dev-guide/css-topics/css-overview.md
  • guides/v2.3/frontend-dev-guide/css-topics/using-fonts.md
  • guides/v2.3/frontend-dev-guide/theme-best-practice.md
  • guides/v2.2/frontend-dev-guide/css-topics/css-critical-path.md
  • guides/v2.2/frontend-dev-guide/css-topics/css-overview.md
  • guides/v2.2/frontend-dev-guide/css-topics/using-fonts.md
  • guides/v2.2/frontend-dev-guide/theme-best-practice.md

Links to Magento source code

whatsnew
Added the new topic CSS Critical Path to the Frontend Developer Guide.

@devops-devdocs
Copy link
Collaborator

An admin must run tests on this PR before it can be merged.

- Update critical CSS performance improvements;
If there is not `critical.css` for custom theme but there is Luma theme, Luma's `critical.css` will be used.
Critical css file path can also be configured in `di.xml` as a constructor `filePath` argument in `Magento\Theme\Block\Html\Header\CriticalCss` block.

To generate critical CSS for your theme online generators can be used or you can create it by yourself. While creating your own critical CSS adhere to the following principles:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also describe alternatives of generating critical css manually, like:

  1. https://www.npmjs.com/package/penthouse
  2. https://www.npmjs.com/package/critical

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added links to generators but I'm not going to describe how to work with them in this documentation as they are external.

Copy link

@joseborngroup joseborngroup Dec 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for doing this, but I am afraid this is still not very clear, looking at the grunt-critical documentation I wonder if we manually have to copy the html and css of different pages like Homepage, Product Listing page, etc into an html and css file, and then run the grunt task to get the critical css, however this way we will get the critical css of all of the page views inside critical.css , so we will load css that is not needed into some pages, is there a way so the critical.css file only has the critical css for the specific pageview? . Also does this mean we will have to manually copy the html and css contents every time something is changed in the content of a page? and then make a new deployment to production? . Another question is, how do we remove the critical css from styles-l.css and styles-m.css so they are not duplicated in critical.css ?

### Critical CSS loader

There is a loading spinner in critical styles if CSS critical path is enabled in configuration. Loader explains to users that something is still loading and it helps to increase the user experience.
After non-critical CSS is loaded and applied, spinner disappears. External developers should either override `main_css_preloader` block defined in `Magento/Theme/view/frontend/layout/default.xml` or hide loading spinner after non-critical CSS is loaded.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spinner disappears only in case you have css styles from blank theme css, instead you have your own css rule you should hide preloader by data-role='main-css-loader' attribute

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation about reloader updated


### Font head type

`<font>` is added to HTML `<head>` type for the layout in `lib/internal/Magento/Framework/View/Layout/etc/head.xsd`. It means that fonts and icons can be preloaded by default. As a result custom fonts can be delivered faster.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. <font> node is added
  2. all resources added with <font> node will be downloaded with preload html tag, since preload does not use downloaded resource you should ensure that you this resource in css or html DOM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

- Update documentation about fonts and critical css;
@osrecio osrecio added Technical Updates to the code or processes that alter the technical content of the doc New Topic A major update published as an entirely new document labels Jun 12, 2019
@osrecio osrecio self-assigned this Jun 12, 2019
adifucan added 2 commits June 12, 2019 16:31
- Add documentation for 2.2;
- Update using fonts documentation for 2.2;
@keharper keharper added 2.2.x 2.3.x Magento 2.3 related changes and removed Technical Updates to the code or processes that alter the technical content of the doc labels Jun 27, 2019
@dobooth dobooth self-assigned this Jul 16, 2019
adifucan and others added 3 commits July 16, 2019 16:59
- Optimized images;
# Conflicts:
#	guides/v2.2/frontend-dev-guide/css-topics/css-overview.md
#	guides/v2.2/frontend-dev-guide/css-topics/using-fonts.md
#	guides/v2.3/frontend-dev-guide/layouts/layout-types.md
@osrecio
Copy link
Member

osrecio commented Jul 18, 2019

@vzabaznov Can you mark as resolved these conversations? For me the PR is ok from the technical point of view


### `<font>` head type

`<font>` node is added to HTML `<head>` type for layout in `lib/internal/Magento/Framework/View/Layout/etc/head.xsd`. All resources added with `<font>` node will be downloaded with `preload` html attribute. Since preload does not use downloaded resource, you should ensure that this resource is used in CSS or HTML DOM.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @adifucan I am a bit confused on this paragraph. What do you mean 'preload does not use downloaded resources'? What does it use? Which resource should we ensure is used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that preload attribute just specifies resources that your page will need very soon, which you want to start loading early in the page lifecycle. This ensures they are available earlier.
Here I mean that fonts will be preloaded now and you should ensure that they are used in CSS/HTML.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's not obligatory to mention about "Since preload does not use downloaded resource, you should ensure that this resource is used in CSS or HTML DOM." here because preload functionality works in this way.

@dobooth
Copy link
Contributor

dobooth commented Jul 29, 2019

running tests

@dobooth
Copy link
Contributor

dobooth commented Jul 30, 2019

running tests

@dobooth dobooth merged commit 681851d into magento:master Jul 30, 2019
@ghost
Copy link

ghost commented Jul 30, 2019

Hi @adifucan, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@atwixfirster
Copy link
Contributor

atwixfirster commented Sep 13, 2019

@dobooth , could you please clarify what is https://github.com/magento/magento2ce/pull/4310 ? Reference to that PR is provided in the Links to Magento source code section.

Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
2.2.x 2.3.x Magento 2.3 related changes New Topic A major update published as an entirely new document
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants