9

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?

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

3 Answers 3

7

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

3
2

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

2
  • 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 Jun 11, 2016 at 17:02
  • This worked for me. Remember that Magento must be in Default or Production mode. Apr 28, 2017 at 13:52
0

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

Your Answer

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

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