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– shane2016年10月06日 13:38:40 +00:00Commented Oct 6, 2016 at 13:38
3 Answers 3
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
-
would you mind sharing that? I'm facing the same problem.peedee– peedee2016年09月01日 07:51:36 +00:00Commented 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 minifyLewis Pearson– Lewis Pearson2016年09月02日 11:00:31 +00:00Commented 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 :-(peedee– peedee2016年09月10日 16:14:16 +00:00Commented Sep 10, 2016 at 16:14
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
-
2I 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 featureLewis Pearson– Lewis Pearson2016年06月11日 17:02:27 +00:00Commented Jun 11, 2016 at 17:02
-
This worked for me. Remember that Magento must be in Default or Production mode.Casper Skovgaard– Casper Skovgaard2017年04月28日 13:52:31 +00:00Commented Apr 28, 2017 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