2

I merged JS and CSS file Stores -> Configuration -> Advanced -> Developer -> Javascript Settings in production mode of magento2.

Once, I check via view source of the page, I can see the Javascript is merged.

But Still it's show 75 external Javascript scripts via GTMatrix HTTP requests.

So How can i removed that 75 external javascript requests?

Thank you in advance!

3 Answers 3

4

Javascript bundling is a technique that groups separate files in order to reduce the number of HTTP requests that are required to load a page. Bundling is commonly used in today’s “module-based” development where some functionalities are basically split into Modules.

From Admin Panel: In Admin Panel go to Stores -> Configuration -> Advanced -> Developer -> Javascript Settings ->Enable Javascript Bundling

detail

From Terminal:

We have to run the following command

For enable:

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

php bin/magento cache:clean

For disable:

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

php bin/magento cache:clean

Thanks

1

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.

3
  • I have merged js and CSS with production mode. But still I can see many http requests js and css files. How can i reduce the http requests of js and css in magento2? Commented Nov 9, 2017 at 12:34
  • You can change the bundle_size to 3Mb for example in [theme_folder]/etc/view.xml And run the deploy php bin/magento setup:static-content:deploy to clean and refresh pub/static. If you don't have the bundled files after you visit a page than your compilation commands fail from various reasons (one is permissions). I personally don't like minify options in Magento, so I recommend against it. And have your webserver to send gziped static files. It should partially resolve the big size JS file issue. Commented Nov 9, 2017 at 15:29
  • Refer this --> wp.me/p4FAWA-6q Commented Apr 23, 2020 at 11:18
0

You should download these scripts and put on your server and define them in your theme.

1
  • The scripts are already there and those scrip by magento. So I dont think i have to download and have to put server. The site is already live. I just want to remove the many external JavaScript to speed up the site. Can you help me? Commented Nov 4, 2017 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.