Skip to content

CSS load order incorrect using default_head_blocks.xml #1821

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

Closed
chicgeek opened this issue Sep 8, 2015 · 22 comments
Closed

CSS load order incorrect using default_head_blocks.xml #1821

chicgeek opened this issue Sep 8, 2015 · 22 comments
Assignees
Labels
Area: Frontend bug report Event: distributed-cd Distributed Contribution Day Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@chicgeek
Copy link
Contributor

chicgeek commented Sep 8, 2015

For my theme I am loading in two stylesheets: one from a CDN (cdn.css) and one from my theme (local.css). They should be loaded in this order in the DOM but it does not preserve the order indicated by the XML.

This is what I have in default_head_blocks.xml in the correct order:

<css src="https://example.com/cdn.css" src_type="url" />
<css src="css/local.css" />

But in the DOM it does not load in this order: local.css is loaded in first and cdn.css second.

I believe this to be a bug - am I missing additional configuration to set load order for these assets?

I did not find information specific to load order in the documentation. I know in M1 the order specified in the XML would be preserved in the DOM.

@chicgeek chicgeek changed the title CSS load order using default_head_blocks.xml CSS load order incorrect using default_head_blocks.xml Sep 8, 2015
@slavvka
Copy link
Member

slavvka commented Sep 9, 2015

Thank you. This issue has been reported as MAGETWO-42659 internal issue.

@rgoncharuk rgoncharuk added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development CS labels Mar 17, 2016
@maksek
Copy link
Contributor

maksek commented May 9, 2016

Hi @chicgeek, did you find answer or workaround on the issue you reported?

@chicgeek
Copy link
Contributor Author

Hey @maksek,

Yes, definitely a 'workaround'.

If you add an attribute to the internal CSS, it will force it to parse this command after other CSS links. This attribute doesn't itself do anything. I named the attribute as follows, but it could be anything:

<css src="https://example.com/cdn.css" src_type="url" />
<css src="css/local.css" load_last="true" />

@jahvi
Copy link

jahvi commented Jun 10, 2016

Is this still an issue? I'm wondering how I can make sure some external fonts get loaded before the regular style-m.css and style-l.css files.

@chicgeek
Copy link
Contributor Author

@jahvi Did you see the workaround I posted just above your comment? Have you tried this, or do all CSS instructions get loaded before your fonts?

Alternately, the font-display attribute for @font-face may be of interest to you:

@jahvi
Copy link

jahvi commented Jun 11, 2016

@chicgeek It does work for 'new' stylesheets but if they've been registered in the parent theme like style-m.css it doesn't seem to do anything. font-display is a good alternative but still being able to control the order would be ideal.

This extension seems to work but I haven't tested it throughly:
https://github.com/quickshiftin/mage2-ordered-assets

@jahvi
Copy link

jahvi commented Jun 13, 2016

It looks like Magento separates the assets into 'groups' before rendering them into the page like, css, scripts, link, etc. You can order the assets within each group using @chicgeek's technique or the extension mentioned above but it doesn't seem like it's possible to load one group before another so if you want to load some google fonts before everything else you'll need to rewrite this functionality.

In my case I ended up copying the @font-face declarations from the google fonts spreadsheet to load it locally instead of using google's CDN. Then copied the styles-m.less stylesheet into my theme and added a @import 'source/_google-fonts.less'; statement before everything else.

@tlygnersjo
Copy link

I've got the same problem, while trying to load Google Fonts (via CDN) before a custom CSS file which has the font-family. But Magento does the reverse so that the font won't work.

I'm using Magento 2.1.2. Is there an upcoming fix for this?

@magento-engcom-team magento-engcom-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report Area: Frontend Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Sep 11, 2017
@magento-engcom-team magento-engcom-team added Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Sep 29, 2017
@JanisE
Copy link
Contributor

JanisE commented Jan 23, 2018

Waiting for this to get sorted out.

@magento-engcom-team magento-engcom-team added the Event: distributed-cd Distributed Contribution Day label Feb 28, 2018
@SerhiyDmytruk
Copy link
Contributor

#distributed-cd

@magento-engcom-team
Copy link
Contributor

@SergeyDmitruk thank you for joining. Please accept team invitation here and self-assign the issue.

@magento-engcom-team
Copy link
Contributor

Hi @chicgeek. Thank you for your report.
The issue has been fixed in #14290 by @SergeyDmitruk in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.5 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Apr 20, 2018
magento-team pushed a commit that referenced this issue Apr 20, 2018
…1821 #14290

 - Merge Pull Request #14290 from SergeyDmitruk/magento2:2.2-develop
 - Merged commits:
   1. 71a6cb8
ihor-sviziev pushed a commit to ihor-sviziev/magento2 that referenced this issue Apr 23, 2018
Added new attribute 'order' for set loading order .
Those attribute resolve issue about render files for some order.
ihor-sviziev pushed a commit to ihor-sviziev/magento2 that referenced this issue Apr 23, 2018
ihor-sviziev pushed a commit to ihor-sviziev/magento2 that referenced this issue Apr 23, 2018
ihor-sviziev pushed a commit to ihor-sviziev/magento2 that referenced this issue Apr 23, 2018
@ishakhsuvarov ishakhsuvarov added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Sep 11, 2018
@ishakhsuvarov
Copy link
Contributor

Hi @chicgeek. Thank you for your report.
The issue has been fixed in #17829 by @nmalevanec in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

magento-engcom-team added a commit that referenced this issue Sep 11, 2018
…d_blocks.xml #1821 #17829

 - Merge Pull Request #17829 from nmalevanec/magento2:2.3-develop-PR-port-14290
 - Merged commits:
   1. d3e24ed
@BenSpace48
Copy link
Contributor

@ishakhsuvarov - Can you confirm if this also affects other filetypes or only CSS?

@jahvi
Copy link

jahvi commented Sep 18, 2018

@BenSpace48 Looking at the committed changes it looks like all the nodes are ordered and then outputted so it should affect all types.

@rssawhney
Copy link

rssawhney commented Jul 15, 2019

@magento-engcom-team it is not working for <script> tags in default.xml

@Eddcapone
Copy link

Does not work. How can I load bootstrap first?

@chicgeek
Copy link
Contributor Author

chicgeek commented Mar 7, 2020

@Eddcapone Did you try the workaround? (Note: I've not tried this recently.)

@Eddcapone
Copy link

Eddcapone commented Mar 9, 2020

@Eddcapone Did you try the workaround? (Note: I've not tried this recently.)

The workaround shows how to load a script last, but I need my bootstrap script loaded before style-m.css and style-l.css. Otherwise it will override some stuff, e.g. it changes the color of a tag to blue.

@hafiz-rusli
Copy link

hafiz-rusli commented Apr 6, 2020

@Eddcapone Did you try the workaround? (Note: I've not tried this recently.)

The workaround shows how to load a script last, but I need my bootstrap script loaded before style-m.css and style-l.css. Otherwise it will override some stuff, e.g. it changes the color of a tag to blue.

is not working as expected. please fix it

@zigojacko
Copy link

zigojacko commented Apr 15, 2020

This is not fixed.

And I'm developing a site on Magento 2.3.4.

Hey @maksek,

Yes, definitely a 'workaround'.

If you add an attribute to the internal CSS, it will force it to parse this command after other CSS links. This attribute doesn't itself do anything. I named the attribute as follows, but it could be anything:

<css src="https://example.com/cdn.css" src_type="url" />
<css src="css/local.css" load_last="true" />

I can confirm that this workaround does fix the issue however, thanks @chicgeek 👍

@Eddcapone
Copy link

Still not fixed in magento 2.3.5 ? Please reopen the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Frontend bug report Event: distributed-cd Distributed Contribution Day Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests