0

I have merge and minify CSS enabled and I would like to know if is there a way to exclude a specific CSS file from the final merged file, but only for the homepage?

I know how to remove a CSS file from the header via XML layout...

<remove src="css/styles-m.css" />

But can you remove/exclude this from the final compiled CSS file, just for the homepage?

Thanks!

  • for my knowledge is no way – xanka May 30 at 9:53
0

If it helps anybody (using Magento 2.1.4), I managed to do this by first adding my CSS file to the exclude list in my view.xml

<exclude>
    <item type="file">Module_Name::css/stylesheet.css</item>
</exclude>

I then created a new cms_index_index.xml and put it in

app/design/frontend/name/theme-name/Magento_Cms/layout

Then added this to remove the file from the homepage...

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
    <remove src="Module_Name::css/stylesheet.css"/>
</head>

I thought this would mean that the file is then not minified and merged for all other pages, but no... it still appears in my merged and minified master CSS file for all other pages (except the homepage)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.