Where is the block with CSS and JS in the <head></head> rendered? And how to change the order of the elements from that section?

enter image description here

(this screenshot is from Magento 2 demo)

I'd like to change the order of elements in that section (and add more elements at the end) but I couldn't find any template file responsible for that part of the head, so it seems like it's rendered somewhere else.

A few elements from the head (e.g. the viewport meta tag) are added in this layout file vendor\magento\module-theme\view\frontend\layout\default_head_blocks.xml:

    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <css src="mage/calendar.css"/>
    <script src="requirejs/require.js"/>

A few other elements are added in this layout file vendor\magento\theme-frontend-blank\Magento_Theme\layout\default_head_blocks.xml:

    <css src="css/styles-m.css"/>
    <css src="css/styles-l.css" media="screen and (min-width: 768px)"/>
    <css src="css/print.css" media="print"/>
  1. But what decides that in the end on the frontend the requirejs/require.js is placed after css/styles-l.css? Where is the code responsible for that?

  2. Where is this element added to the head?

<link rel="stylesheet" type="text/css" media="all" href="http://magento2-demo.nexcess.net/pub/media/styles.css" />

I know it is taken from the Scripts and Style Sheets field from the admin panel: Content -> Design -> Configuration -> HTML Head. But what decides that it is displayed right after requirejs/require.js and not after other CSS assets like css/print.css?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.