Magento – Remove merged css and js from layout in magento2

layoutmagento2merge-cssremove

I have enabled js and css merging and bundling from the configuration.
we can remove particular js or css using below code.

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

But when i try same for removing merged js or css file it is not working,
is there any other way to remove that merged css and js files from layout or any other way.

Best Answer

Exclude js file from the bundle by adding the js file in Theme_Directory/etc/view.xml

<exclude>
<item type="file">Mage_Storelocator::js/googlemap.min.js</item>
</exclude>

Exclude js file from minification in config.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <dev>
            <js>
                <minify_exclude>
                    <tiny_mce>
                     /tiny_mce/
                    </tiny_mce>
                </minify_exclude>
            </js>
        </dev>
    </default>
</config>

You have not excluded the files but you have removed them.

So to exclude the files specified by you from merging/bundling you can add those files to exclude list in your Theme_Directory/etc/view.xml so that they can be loaded individually

<exclude>
    <item type="file">Module_Name::css/name.css</item>
    <item type="file">Module_Name::js/name.js</item>
    <item type="file">Vendor_Module::js/name.js</item>
</exclude>

So if you have minified your files please specify the file name as css/name.min.css or js/name.min.js

enter image description here

I have enabled minification and merge in Magento 2.3.1 and I have excluded this file which is loading separately rather than merge file

<item type="file">Magento_Catalog::js/product/list/toolbar.min.js</item>
Related Topic