I've been struggling for a while with minify javascript on magento 2. The admin option for minification doesn't work so I've been looking for another solution. I've tried a gulp script to do it but this is causing issues with require js where certain files are not ready in time to be included.

Has anyone found a solution for minifying javascript on magento 2?

  • Magento's ultra-modular approach cannot create perf wins by design, I'm afraid. – shane Oct 6 '16 at 13:38

In the end we used a gulp script we wrote ourselves that looks for every javascript file and minifies it. Looks like this is the only way to do it for now without dealing with the bugs the built in magento config option has.

This was our eventual gulp file solution: https://gist.github.com/lewisp6/b7c50b4d82ef4d3d5d6dc888e8d1bdba

| improve this answer | |

I think all that you need is enable "Enable JavaScript Bundling" and "Minify JavaScript Files" options in system configuration on website level in System Configuration > ADVANCED > Developer > JavaScript Settings section and redeploy static content

| improve this answer | |
  • 2
    I wish it were that simple, unfortunately this feature doesn't work on magento 2 for us, have you had any success with it? There are a number of issues on the m2 GitHub repo around problems with this feature – Lewis Pearson Jun 11 '16 at 17:02
  • This worked for me. Remember that Magento must be in Default or Production mode. – Casper Skovgaard Apr 28 '17 at 13:52

One option could be to use PageSpeed plugin from Google to minify js. https://developers.google.com/speed/pagespeed/module/filter-js-minify

| improve this answer | |

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.