From the Magento root directory, switch to production mode:
php bin/magento deploy:mode:set production
php -f bin/magento config:set dev/js/enable_js_bundling 1
php -f bin/magento config:set dev/js/minify_files 1
Enable cache busting on static file URLs. This ensures users get the latest version of the assets anytime they update:
php -f bin/magento config:set dev/static/sign 1
For example, when
Sign Static Filesis disabled (which is the default:
config:set dev/static/sign 0), the URL to a static file might look like this:
/static/frontend/Magento/luma/en_US/mage/dataPost.js. But when you enable the setting (
config:set dev/static/sign 1), the same URL might look something like this:
static/version40s2f9ef/frontend/Magento/luma/en_US/mage/dataPost.js, with a version number added as shown. The next time this file is updated (with
bin/magento setup:static-content:deploy), a new version will be generated, causing the browser to download a new file from the server, thus busting the browser’s cache.
How bundling works in Magento
<exclude> node in the
The following code snippet from Magento’s Luma theme shows the types of files you should exclude from the bundling process.
Setting bundle file size
bundle_size variable controls the file size of the generated bundles.
Specifying a large
bundle_size reduces the number of bundles generated, but generates larger file sizes.
Specifying a smaller
bundle_size generates more bundles with a smaller file sizes.
The goal is to balance the number of bundles to download with the size of each bundle. As a rule of thumb, each bundle should be at least 100 kB.
Fine tuning your theme
There are many ways to tune your theme using the
For example, the Magento Luma theme is configured to work well for all pages, but you can maximize browser performance for home, catalog, or product pages by adding items to or removing items from the
- Create a blank page with the layouts you would like to tune.
- Use the results of that comparison to build your exclude list.