How to Exclude Particular File from JS Bundling in Magento2

In this article, I will explain How to Exclude Particular File from Js Bundling in Magento2.

JS bundling in Magento 2 combines multiple JavaScript files into a single, or fewer, files. This reduces the number of separate requests the browser needs to make to load all the necessary scripts for the site, thus speeding up the loading process. This can significantly improve page load times and overall user experience.

How to Exclude Particular File from JS Bundling in Magento2?

I assume that you have created a custom theme. Now you need to add the below code inside  view.xml file at app/design/frontend/Vendor/themename/etc directory.

<exclude>
    <!-- To exclude whole directory -->
    <item type="directory">Vendor_Modulename::js</item>
    <!-- To exclude specific file -->
    <item type="file">Vendor_Modulename::jquery/jquery.min.js</item>
</exclude>

Now, this JS file and all the JS files within the directory will not be merged in JS bundling. You can add multiple files and directories based on your requirements inside the exclude tag.

You may also like this:

I hope this blog clearly explains how to exclude specific files from JS bundling in Magento 2. If I missed anything or need to add more information, please feel free to leave a comment on this blog, and I’ll respond with a proper solution.

Rate this post