magento2: CSS load order incorrect using default_head_blocks.xml
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.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 2
- Comments: 22 (11 by maintainers)
Commits related to this issue
- ENGCOM-1219: CSS load order incorrect using default_head_blocks.xml #1821 #14290 - Merge Pull Request magento/magento2#14290 from SergeyDmitruk/magento2:2.2-develop - Merged commits: 1. 71a6cb8c... — committed to magento/magento2 by magento-engcom-team 6 years ago
- magento/magento2#14290: CSS load order incorrect using default_head_blocks.xml #1821 — committed to magento/magento2 by VladimirZaets 6 years ago
- magento/magento2#14290: CSS load order incorrect using default_head_blocks.xml #1821 — committed to magento/magento2 by VladimirZaets 6 years ago
- magento/magento2#14290: CSS load order incorrect using default_head_blocks.xml #1821 — committed to magento/magento2 by VladimirZaets 6 years ago
- ENGCOM-1219: CSS load order incorrect using default_head_blocks.xml #1821 #14290 — committed to magento/magento2 by sidolov 6 years ago
- Fix bug #1821 Added new attribute 'order' for set loading order . Those attribute resolve issue about render files for some order. — committed to ihor-sviziev/magento2 by SerhiyDmytruk 6 years ago
- magento/magento2#14290: CSS load order incorrect using default_head_blocks.xml #1821 (cherry picked from commit 51c78b9) — committed to ihor-sviziev/magento2 by VladimirZaets 6 years ago
- magento/magento2#14290: CSS load order incorrect using default_head_blocks.xml #1821 (cherry picked from commit 21cb3af) — committed to ihor-sviziev/magento2 by VladimirZaets 6 years ago
- magento/magento2#14290: CSS load order incorrect using default_head_blocks.xml #1821 (cherry picked from commit ad82a7a) — committed to ihor-sviziev/magento2 by VladimirZaets 6 years ago
- ENGCOM-2891: [Forwardport] CSS load order incorrect using default_head_blocks.xml #1821 #17829 - Merge Pull Request magento/magento2#17829 from nmalevanec/magento2:2.3-develop-PR-port-14290 - Merge... — committed to magento/magento2 by magento-engcom-team 6 years ago
- ENGCOM-2891: [Forwardport] CSS load order incorrect using default_head_blocks.xml #1821 #17829 — committed to magento/magento2 by sidolov 6 years ago
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-facedeclarations from the google fonts spreadsheet to load it locally instead of using google’s CDN. Then copied thestyles-m.lessstylesheet into my theme and added a@import 'source/_google-fonts.less';statement before everything else.Still not fixed in magento 2.3.5 ? Please reopen the issue.
This is not fixed.
And I’m developing a site on Magento 2.3.4.
I can confirm that this workaround does fix the issue however, thanks @chicgeek 👍
is not working as expected. please fix it <css src="css/bootstrap.min.css" order="1" />
@BenSpace48 Looking at the committed changes it looks like all the nodes are ordered and then outputted so it should affect all types.
#distributed-cd
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.
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: