-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Document CSS critical path #4726
Document CSS critical path #4726
Conversation
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: |
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.
can you also describe alternatives of generating critical css manually, like:
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.
Added links to generators but I'm not going to describe how to work with them in this documentation as they are external.
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.
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. |
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.
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
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.
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. |
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.
<font>
node is added- 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
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.
Fixed
- Update documentation about fonts and critical css;
- Add documentation for 2.2; - Update using fonts documentation for 2.2;
- 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
@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. |
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.
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?
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 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.
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.
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.
running tests |
running tests |
Hi @adifucan, thank you for your contribution! |
@dobooth , could you please clarify what is https://github.com/magento/magento2ce/pull/4310 ? Reference to that PR is provided in the Thank you! |
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
Links to Magento source code
whatsnew
Added the new topic CSS Critical Path to the Frontend Developer Guide.