Magento2: Magento2 JS minification

Created on 27 Mar 2015  路  9Comments  路  Source: magento/magento2

Enabled JS Minification in the admin (along with bundling.. whatever that is), along with merging.

However when I look in firebug net I see a merged JavaScipt file but also about another 20 files, such as translate.js etc.

needs update

Most helpful comment

Hi, @craigcarnell.
While "Merge JavaScript Files" option deal with files declared via layouts, as @buskamuza has mentioned, the second option "Enable Javascript Bundling" deals with JavaScript files which are not included via layouts but loaded using RequireJS.
There are two preconditions for using this option properly:

  1. You need to run dev/tools/Magento/Tools/View/deploy.php script.
  2. Switch from "default" or "developer" mode to "production" mode.

Good to know:
There are few configuration options available to configure bundling per theme (eg, app/design/adminhtml/Magento/backend/etc/view.xml)
When deploy script is running, we scan through entire Magento directory and assemble JavaScript files into bundles (according to variable option "js_bundle_size"). And there is another setting to specify a list of JavaScript files which should be excluded from bundling (so even if you make all right some files still will be loading asynchronously).

Since, the bundling feature is still in development, you won't find a documentation yet available. But within some nearest release it will be shipped to public resource.

If you need more details, you may ask questions here so far.

Thank you.

All 9 comments

Hi, @craigcarnell.
Merging is applicable only for assets included via layouts. If the asset is included directly on a page or using RequireJS technique, it will not be merged. So it may happen that some of the files that you see loaded separately are included in that way.

Hi, @craigcarnell.
While "Merge JavaScript Files" option deal with files declared via layouts, as @buskamuza has mentioned, the second option "Enable Javascript Bundling" deals with JavaScript files which are not included via layouts but loaded using RequireJS.
There are two preconditions for using this option properly:

  1. You need to run dev/tools/Magento/Tools/View/deploy.php script.
  2. Switch from "default" or "developer" mode to "production" mode.

Good to know:
There are few configuration options available to configure bundling per theme (eg, app/design/adminhtml/Magento/backend/etc/view.xml)
When deploy script is running, we scan through entire Magento directory and assemble JavaScript files into bundles (according to variable option "js_bundle_size"). And there is another setting to specify a list of JavaScript files which should be excluded from bundling (so even if you make all right some files still will be loading asynchronously).

Since, the bundling feature is still in development, you won't find a documentation yet available. But within some nearest release it will be shipped to public resource.

If you need more details, you may ask questions here so far.

Thank you.

@craigcarnell, do you have another questions or we can close this issue?

Closed. There is no response from reporter. @craigcarnell, feel free to reopen if still have issues with JS minification .

@vpelipenko When I enable the merge and bundling of JavaScript files in beta4, the admin system menu no longer responds. There is no errors in my console. It will not slide across.

I would preferably like frontend and back end merging/bundling being moved into separate menu options, as this can issue often occurs if there is a mistake in any javascript, stopping javascript running in the admin.

@vkorotun How do you switch to "production" mode?

If anyone else comes across this post.....

./bin/magento deploy:mode:set production

When I have JS Bundling enabled, my .js file size has whopping 13+ MB!!! If I gzip it, it has 3+ MB, but that is a lot of slowdown time on first-page load and lots of bandwidth cut-off on each sach file load!

image 2016-05-01 15 03 44

I have the same problem as above. I've opened a new bug for it: 4506

And the
<vars module="Js_Bundle"> <var name="bundle_size">2MB</var> </vars>
in theme's view.xml is completely ignored!

Was this page helpful?
0 / 5 - 0 ratings