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?

asked Jun 10, 2016 at 15:02
1
  • Magento's ultra-modular approach cannot create perf wins by design, I'm afraid. Commented 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

answered Jul 11, 2016 at 8:37
3
  • would you mind sharing that? I'm facing the same problem. Commented Sep 1, 2016 at 7:51
  • @peedee sure it's only really basic gist.github.com/lewisp6/b7c50b4d82ef4d3d5d6dc888e8d1bdba if you have any thoughts on how we could make it better we'd love to here it. Also we didn't manage to combine the files which we would of liked, only minify Commented Sep 2, 2016 at 11:00
  • thanks. I've asked my own question about this at magento.stackexchange.com/q/134206/24432 but so far no answer :-( Commented Sep 10, 2016 at 16:14
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

answered Jun 10, 2016 at 16:28
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 Commented Jun 11, 2016 at 17:02
  • This worked for me. Remember that Magento must be in Default or Production mode. Commented 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

answered Jun 11, 2016 at 1:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.