Stratus Magento 2 Guides - Using Baler to Speed Javascript Delivery

Baler is a module bundler and preloader for Magento 2 installations. It is an open-source add-on that intelligently bundles Javascript based on where and how it is needed.

The result of this bundling is faster page speed times, which can improve customer experiences and Google rankings.

Bundling can only be activated on a Production environment.

Installing Baler

To install Baler:

  1. Clone the current Baler Repository.

    git clone https://github.com/magento/baler.git

  2. Change to the Baler directory and install using npm.

    npm install

  3. Check to confirm you have node.js version 10.12.0 or later.

    ~/baler/bin$ ./baler baler requires a version of node.js >= 10.12.0. You're currently using v8.16.0

    For more on using node.js, see Node.js Node Version Manager.

  4. Change to the Magento 2 document root and run Baler.

    :~/public_html$ /srv/baler/bin/baler

  5. Clear Magento and Redis cache.

    ~/public_html$ n98-magerun2 cache:clean

    ~/public_html$ n98-magerun2 cache:flush

    ~/public_html$ redis-cli flushall

  6. Install the Magento 2 module that will handle bundlings.

    composer config repositories.baler vcs https://github.com/adifucan/m2-baler

    composer require magento/module-baler:dev-master

  7. Activate module.

    n98-magerun2 module:enable Magento_Baler

  8. Run deployment process.

    n98-magerun2 setup:upgrade

    n98-magerun2 setup:di:compile

    n98-magerun2 setup:static-content:deploy

  9. Clear Magento and Redis cache again.

    ~/public_html$ n98-magerun2 cache:clean

    ~/public_html$ n98-magerun2 cache:flush

    ~/public_html$ redis-cli flushall

  10. Run the set configuration command.

    php bin/magento config:set dev/js/enable_baler_js_bundling 1

  11. Run Baler again.

    $ /srv/baler/bin/baler build

  12. Disable builtin Magento 2 javascript minification, merging, and bundling.

    php bin/magento config:set dev/js/minify_files 0

    php bin/magento config:set dev/js/enable_js_bundling 0

    php bin/magento config:set dev/js/merge_files 0

  13. Clear Magento and Redis cache yet again.

    ~/public_html$ n98-magerun2 cache:clean

    ~/public_html$ n98-magerun2 cache:flush

    ~/public_html$ redis-cli flushall


Last modified January 1, 0001