0

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!

0

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

  • 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? – user2710761 Nov 4 '17 at 10:12
0

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.

  • 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? – user2710761 Nov 9 '17 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. – obscure Nov 9 '17 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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