Open nurullah opened 1 year ago
Hi @nurullah. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x release@magento I am working on this
Join Magento Community Engineering Slack and ask your questions in #github channel. :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. :clock10: You can find the schedule on the Magento Community Calendar page. :telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
@magento give me 2.4-develop instance
Hi @Usik2203. Thank you for your request. I'm working on Magento instance for you.
Hi @Usik2203, here is your Magento Instance: https://8464f07e498f3fc9d0b2db82f15bdb09.instances-prod.magento-community.engineering Admin access: https://8464f07e498f3fc9d0b2db82f15bdb09.instances-prod.magento-community.engineering/admin_9e1a Login: 802c155e Password: a2220159c4ba
From my experience defer only work with script tag ! I'm not to try with css. So i think you may to want use critical css right ? Not sure it's fit with your case or you just want specific priority load for some speicifc css file
From my experience defer only work with script tag ! I'm not to try with css. So i think you may to want use critical css right ? Not sure it's fit with your case or you just want specific priority load for some speicifc css file
It's easier to know which CSS files to defer than to know which CSS codes are absolutely necessary. I used critical CSS but it causes CLS issues when not prepared perfectly.
so from my understanding we need somehow to specific defer to css link
When we add defer attribute css will render output
->
<link rel="stylesheet" media="all" type="text/css" href="css/intl-tel-input.css" as="style" onload="this.onload=null;this.media='all';this.rel='stylesheet'">
without specific link css will output as normal
so from my understanding we need somehow to specific defer to css link When we add defer attribute css will render output ->
<link rel="stylesheet" media="all" type="text/css" href="css/intl-tel-input.css" as="style" onload="this.onload=null;this.media='all';this.rel='stylesheet'">
without specific link css will output as normal
Rel attribute must have preload
value in your example. I was trying to get that output with the current head elements but I can't add onload
attribute. Because it is not supported in <css .. />
and <link .. />
elements. So, I added the below XML code in the default_head_blocks.xml
file.
<css src="css/intl-tel-input.css" rel="preload" as="style" />
But I got the below output: Preload attribute was defined twice, i couldn't pass the onload
attribute and i couldn't add the <noscript>...</noscript>
definition that will work if JS turned off in the browser.
After more dig in code base i see team already have some work on this You can see this line https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Theme/Controller/Result/AsyncCssPlugin.php#L104 Note sure this is complete cover all edge-cases
I don't see any check defer property anywhere else in php code -> for css type
in my opinion this one should consider as bug -> defer attribute not correct render for css link Scenario 1: No enable critical css -> If no specific link defer -> Work as current. If link css defer specific then reformat link Scenario 2: Enable critical css -> critical asset will go first -> Defer specific link will reformat as nurullah's suggest. Other links non-defer will render as normal
in my opinion this one should consider as bug -> defer attribute not correct render for css link Scenario 1: No enable critical css -> If no specific link defer -> Work as current. If link css defer specific then reformat link Scenario 2: Enable critical css -> critical asset will go first -> Defer specific link will reformat as nurullah's suggest. Other links non-defer will render as normal
I worked Scenario 1 method in my local environment but it's not ready for the pull request. When I find the some spare time, I will send pull request for this issue.
@magento I am working on this.
Hi @engcom-Hotel. 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:
Area: XXXXX
label to the ticket, indicating the functional areas it may be related to.2.4-develop
branch@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure. 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.Issue: Confirmed
once verification is complete. Hello @nurullah,
Thanks for the report and collaboration!
@mrtuvn thanks for your inputs on this issue.
We have tried to reproduce the issue via adding defer=true
attribute to calendar.css as well as tried to add rel="preload" as="style"
but it does seems to work as expected. Please find the below screenshot for reference:
While adding defer=true
It still shows the priority as Highest
:
While adding rel="preload" as="style"
It is adding rel
attribute 2 times as below:
Hence confirming the issue.
Thanks
:x: Something went wrong. Cannot create Jira issue.
Hello @nurullah,
Thanks for the report and collaboration!
@mrtuvn thanks for your inputs on this issue.
We have tried to reproduce the issue via adding
defer=true
attribute to calendar.css as well as tried to addrel="preload" as="style"
but it does seems to work as expected. Please find the below screenshot for reference:While adding
defer=true
It still shows the priority as
Highest
:While adding
rel="preload" as="style"
It is adding
rel
attribute 2 times as below:
Hence confirming the issue.
Thanks
Hello.
HTML link element doesn't have defer
attribute. We need to use that hacky method in the image below, when we want to defer CSS files.
In this example, rel
attribute must be defined only one time. Because rel="preload"
attribute tells to the browser load this file but don't render until the onload function run. The onload
function changes the rel attribute to the stylesheet
and this CSS file starts rendering after the whole document is loaded.
Summary
While I searching for ways to defer non-critical CSS files, I found that magento2 has a
defer
attribute in the head.xsd file. This means I can write the following code in thedefault_head_blocks.xml
without any errors.But I realized that this
defer
attribute unfortunately has no effect on the CSS element. I just wondering the purpose of allowing us to use this attribute. Do you have any future plans about this attribute for any of the linkType elements (css, link, font)?Examples
https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/View/Layout/etc/head.xsd#L11C27-L11C27
Proposed solution
After editing the Renderer.php file, we can get the output as follows by writing the code above. With this way, we can defer non-critical render-blocking CSS files on the first load.
Release note
No response
Triage and priority