Location and compilation of CSS files
In the previous chapter, I mentioned that you can basically do anything with the platform in the PHTML files. It’s possible, but not recommended, to add any code or even any CSS file in any place of a PHTML file.
It is a bad practice, but unfortunately, some third-party extension vendors like to inject or add custom CSS files through the PHTML files.
My goal, for you and your clients, is to make sure that things are done right. Do you remember which block, from Chapter 4, is responsible for adding and removing static files from the page <
HEAD>
tag?
I kind of answered that in the question itself, as it is the <head>
block, and one should only add or remove CSS files strictly by using Layout XML. If you must inject the CSS file in some other way, it probably means that something is off.
The main CSS files are defined in the Blank theme in the file vendor/magento/theme-frontend-blank/Magento_Theme/layout/default_head_blocks...