{"id":27581,"date":"2024-09-30T08:56:09","date_gmt":"2024-09-30T12:56:09","guid":{"rendered":"https:\/\/plumrocket.com\/docs\/?p=27581"},"modified":"2024-09-30T09:33:30","modified_gmt":"2024-09-30T13:33:30","slug":"how-to-set-up-javascript-bundling-in-magento-2-cloud","status":"publish","type":"post","link":"https:\/\/plumrocket.com\/docs\/magento-page-speed-optimizer\/v1\/troubleshooting\/configuring-js-bundles-in-magento-cloud","title":{"rendered":"How to Set Up JavaScript Bundling in Magento 2 Cloud"},"content":{"rendered":"\n<p>Bundling JavaScript files on your Magento 2 store significantly reduces the number of server requests and speeds up page loading time. Although Magento provides a native JS bundling functionality to enhance website performance, it isn\u2019t advanced enough to achieve optimal results and significantly improve user experience.<\/p>\n\n\n\n<p>Our <a href=\"\/magento-page-speed-optimizer\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 Page Speed Optimizer extension<\/a> boosts the default Magento JS Bundling functionality with more advanced techniques that load only necessary JS code. This minimizes server requests and significantly improves page load times, delivering an even faster user experience. However, the configuration of JS bundling requires additional steps when performed on a Magento 2 Cloud environment. In this article, we will provide all the steps in detail to guarantee easy and safe implementation.<\/p>\n\n\n\n<h2 id=\"h-why-js-bundling-setup-is-different-on-magento-cloud\">Why JS Bundling Setup is Different on Magento Cloud<\/h2>\n\n\n\n<p>JS bundle creation on Magento Cloud slightly differs from <a href=\"\/docs\/magento-page-speed-optimizer\/v1\/configuration#javascript-smart-bundling\" target=\"_blank\" rel=\"noreferrer noopener\">the advanced JS bundling process in the Plumroclet extension<\/a>, which is designed for automatic setup in Magento on-premises environments. <\/p>\n\n\n\n<p>The main challenge lies in the Magento Cloud\u2019s restriction on file editing permissions. These limitations may cause issues in executing standard commands and, consequently, disrupt the setup of JS file mapping. However, mapping JS files is crucial as it allows the extension to identify which files are necessary for specific pages, allowing it to create optimized bundles.<\/p>\n\n\n\n<p>As a result, the JS bundle configuration stage should be different for Magento Cloud. In this tutorial, we will cover 2 methods for setting up JS bundling in Magento Cloud:<\/p>\n\n\n\n<ol><li>Enable SCD on demand in the staging environment.<\/li><li>Use a local development environment.<\/li><\/ol>\n\n\n\n<h2 id=\"h-setting-up-js-bundles-on-magento-2-cloud\">Setting Up JS Bundles on Magento 2 Cloud<\/h2>\n\n\n\n<h3 id=\"h-method-1-enable-scd-on-demand-in-the-staging-environment\">Method 1: Enable SCD on demand in the staging environment<\/h3>\n\n\n\n<p>This method is recommended and requires less time and effort to complete. Note that all actions should be performed exclusively on the stage\/dev contained in the Magento Cloud, which is a copy of the production.<\/p>\n\n\n\n<p><strong>Step 1. Enable Static Content Deployment<\/strong><\/p>\n\n\n\n<p>First, you should enable <a href=\"https:\/\/experienceleague.adobe.com\/en\/docs\/commerce-cloud-service\/user-guide\/develop\/deploy\/static-content#setting-the-scd-on-demand\" target=\"_blank\" rel=\"noreferrer noopener\">static content deployment<\/a> for this environment on demand. To do this, follow the next steps:<\/p>\n\n\n\n<div class=\"wp-block-group pr-notice pr-notice-info\"><div class=\"wp-block-group__inner-container\">\n<p class=\"pr-notice-title\">Step-by-step guide:<\/p>\n\n\n\n<ol><li>Locate the <code>.magento.env.yaml<\/code> file in your staging or development environment.<\/li><li>Enable the <code>SCD_ON_DEMAND<\/code> variable in the file.<\/li><li>Apply new configurations. <strong>Please note<\/strong>: this variable has priority over other static content deployment configurations and disables its execution when the environment is deployed.<\/li><\/ol>\n<\/div><\/div>\n\n\n\n<p><strong>Step 2. Configure Smart JS Bundling<\/strong><\/p>\n\n\n\n<p>Then, when <code>SCD_ON_DEMAND<\/code> is enabled and active, you should complete all the steps described in the <a href=\"\/docs\/magento-page-speed-optimizer\/v1\/configuration#javascript-smart-bundling\" target=\"_blank\" rel=\"noreferrer noopener\">Smart JS Bundling documentation<\/a>.<\/p>\n\n\n\n<p><strong>Step 3. Deploy changes to production<\/strong><\/p>\n\n\n\n<p>Lastly, after JS bundles are created, we recommend checking if the website functions properly. If everything works as expected, you need to download the <code>pr_require_js_module table<\/code> content and paste it into the production database.<\/p>\n\n\n\n<p>Now, the process of configuring bundles for Magento 2 Cloud is complete. You just need to enable them and regenerate the static content for the changes to take effect. Use this command to regenerate static content:<br><\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">setup:static-content:deploy<\/code><\/pre><\/div>\n\n\n\n<h3 id=\"h-method-2-enable-scd-on-demand-in-the-staging-environment\">Method 2: Enable SCD on demand in the staging environment<\/h3>\n\n\n\n<p><strong>Step 1. Set up your local development environment<\/strong><\/p>\n\n\n\n<p>Set up your local dev environment and make sure it\u2019s up to date and matches the production.<\/p>\n\n\n\n<p><strong>Step 2. Set up JS Bundles on your local environment<\/strong><\/p>\n\n\n\n<p>At this point, complete all the steps described in the <a href=\"\/docs\/magento-page-speed-optimizer\/v1\/configuration#javascript-smart-bundling\" target=\"_blank\" rel=\"noreferrer noopener\">Setti<\/a><a href=\"\/docs\/magento-page-speed-optimizer\/v1\/configuration#javascript-smart-bundling\">ng Up JS bundles<\/a> section of the <a href=\"\/magento-page-speed-optimizer\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 Page Speed Optimizer extension<\/a> configurations.<\/p>\n\n\n\n<p><strong>Step 3. Deploy changes to production<\/strong><\/p>\n\n\n\n<p>After JS bundles are created, we recommend checking if the website functions properly. If everything works as expected, you need to download the <code>pr_require_js_module<\/code> table content and paste it into the production environment database.<\/p>\n\n\n\n<p>Now, the process of configuring bundles for Magento 2 Cloud is complete. You just need to enable them and regenerate the static content for the changes to take effect. Use this command to regenerate static content:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-bash\">setup:static-content:deploy<\/code><\/pre><\/div>\n\n\n\n<h2 id=\"h-conclusion\">Conclusion<\/h2>\n\n\n\n<p>The JS bundle configuration process is generally similar to the default process. However, in the Magento Cloud scenario, it requires some additional preparation steps in the development environment and manual manipulations with the <code>pr_require_js_module<\/code> database table.<\/p>\n\n\n\n<p>It is also worth noting that regenerating JS bundles are highly recommended not only for the initial setup of the Magento 2 Google Page Speed Optimizer extension but also whenever there are changes to the JavaScript files on the site (such as when a module is installed\/updated or when new files are added). This helps ensure optimal performance and avoid potential JS issues.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bundling JavaScript files on your Magento 2 store significantly reduces the number of server requests and speeds up page loading time. Although Magento provides a native JS bundling functionality to enhance website performance, it isn\u2019t advanced enough to achieve optimal results and significantly improve user experience. Our Magento 2 Page Speed Optimizer extension boosts the &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/plumrocket.com\/docs\/magento-page-speed-optimizer\/v1\/troubleshooting\/configuring-js-bundles-in-magento-cloud\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Set Up JavaScript Bundling in Magento 2 Cloud&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[370],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v17.2 (Yoast SEO v17.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Set Up JavaScript Bundling in Magento 2 Cloud<\/title>\n<meta name=\"description\" content=\"Discover what additional preparation steps are required when configuring Magento 2 Smart JS Bundling by Plumrocket in the Cloud environment.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/plumrocket.com\/docs\/magento-page-speed-optimizer\/v1\/troubleshooting\/configuring-js-bundles-in-magento-cloud\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Set Up JavaScript Bundling in Magento 2 Cloud\" \/>\n<meta property=\"og:description\" content=\"Discover what additional preparation steps are required when configuring Magento 2 Smart JS Bundling by Plumrocket in the Cloud environment.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/plumrocket.com\/docs\/magento-page-speed-optimizer\/v1\/troubleshooting\/configuring-js-bundles-in-magento-cloud\" \/>\n<meta property=\"og:site_name\" content=\"Plumrocket Documentation\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-30T12:56:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-30T13:33:30+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Plumrocket\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Set Up JavaScript Bundling in Magento 2 Cloud","description":"Discover what additional preparation steps are required when configuring Magento 2 Smart JS Bundling by Plumrocket in the Cloud environment.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/plumrocket.com\/docs\/magento-page-speed-optimizer\/v1\/troubleshooting\/configuring-js-bundles-in-magento-cloud","og_locale":"en_US","og_type":"article","og_title":"How to Set Up JavaScript Bundling in Magento 2 Cloud","og_description":"Discover what additional preparation steps are required when configuring Magento 2 Smart JS Bundling by Plumrocket in the Cloud environment.","og_url":"https:\/\/plumrocket.com\/docs\/magento-page-speed-optimizer\/v1\/troubleshooting\/configuring-js-bundles-in-magento-cloud","og_site_name":"Plumrocket Documentation","article_published_time":"2024-09-30T12:56:09+00:00","article_modified_time":"2024-09-30T13:33:30+00:00","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Plumrocket","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/plumrocket.com\/docs\/#website","url":"https:\/\/plumrocket.com\/docs\/","name":"Plumrocket Documentation","description":"Extensions docs, troubleshootings etc.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/plumrocket.com\/docs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/plumrocket.com\/docs\/magento-page-speed-optimizer\/v1\/troubleshooting\/configuring-js-bundles-in-magento-cloud#webpage","url":"https:\/\/plumrocket.com\/docs\/magento-page-speed-optimizer\/v1\/troubleshooting\/configuring-js-bundles-in-magento-cloud","name":"How to Set Up JavaScript Bundling in Magento 2 Cloud","isPartOf":{"@id":"https:\/\/plumrocket.com\/docs\/#website"},"datePublished":"2024-09-30T12:56:09+00:00","dateModified":"2024-09-30T13:33:30+00:00","author":{"@id":"https:\/\/plumrocket.com\/docs\/#\/schema\/person\/c96fccdb89342ae6804272265723eca8"},"description":"Discover what additional preparation steps are required when configuring Magento 2 Smart JS Bundling by Plumrocket in the Cloud environment.","breadcrumb":{"@id":"https:\/\/plumrocket.com\/docs\/magento-page-speed-optimizer\/v1\/troubleshooting\/configuring-js-bundles-in-magento-cloud#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/plumrocket.com\/docs\/magento-page-speed-optimizer\/v1\/troubleshooting\/configuring-js-bundles-in-magento-cloud"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/plumrocket.com\/docs\/magento-page-speed-optimizer\/v1\/troubleshooting\/configuring-js-bundles-in-magento-cloud#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Magento 2 Extensions","item":"https:\/\/plumrocket.com\/magento-extensions"},{"@type":"ListItem","position":2,"name":"Magento 2 Google Page Speed Optimizer","item":"https:\/\/plumrocket.com\/magento-page-speed-optimizer"},{"@type":"ListItem","position":3,"name":"Documentation","item":"https:\/\/plumrocket.com\/docs\/magento-page-speed-optimizer"},{"@type":"ListItem","position":4,"name":"v1","item":"https:\/\/plumrocket.com\/docs\/magento-page-speed-optimizer\/v1"},{"@type":"ListItem","position":5,"name":"Troubleshooting","item":"https:\/\/plumrocket.com\/docs\/magento-page-speed-optimizer\/v1\/troubleshooting"},{"@type":"ListItem","position":6,"name":"How to Set Up JavaScript Bundling in Magento 2 Cloud"}]},{"@type":"Person","@id":"https:\/\/plumrocket.com\/docs\/#\/schema\/person\/c96fccdb89342ae6804272265723eca8","name":"Plumrocket","image":{"@type":"ImageObject","@id":"https:\/\/plumrocket.com\/docs\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/10c44aa45aab391250913d982e552e53?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/10c44aa45aab391250913d982e552e53?s=96&d=mm&r=g","caption":"Plumrocket"}}]}},"_links":{"self":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts\/27581"}],"collection":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/comments?post=27581"}],"version-history":[{"count":10,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts\/27581\/revisions"}],"predecessor-version":[{"id":27593,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts\/27581\/revisions\/27593"}],"wp:attachment":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/media?parent=27581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/categories?post=27581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/tags?post=27581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}