Skip to main content

Set

Admin > Stores > Configuration > Advanced > Developer > Enable JavaScript > Javascript Settings > Bundling = Yes

It will create one file with JS files from theme (JS files loaded with RequireJs) and .html knockout templates from web dir, requirejs-config.js.

Merge JavaScript Files = Yes will merge in one file the JS files you have added in the html head tag from layout .xml files. e.g. http://devdocs.magento.com/guides/v2.2/frontend-dev-guide/layouts/xml-manage.html

Be warned, in developer mode it will create the merged js files on each page request, as a result the pages will be very slow.

Also see exclude tag in theme's folder etc/view.xml. Those paths in exclude are not included in the bundled js files because it would be too big. In Magento 2.0, the bundled js was between 7Mb to 10Mb. Magento 2.1 fixed that. This declaration limits the size of the file:

<vars module="Js_Bundle">
    <var name="bundle_size">1MB</var>
</vars>

You should set your store in production mode before enabling bundle JS.

Daniel Ifrim
  • 3.4k
  • 2
  • 23
  • 36