15

My question is as simple as it says in the title. Its why would Magento choose knockout instead of other frameworks like angular or react?

Is there a specific reason?

Also is this the right platform to ask this question?

1
  • @Ben-Crook Looking forward for your inputs as per latest Magento 2 releases and updates till date. Is there anything concrete launched by the team? Commented Feb 10, 2020 at 6:52

5 Answers 5

6

I believe it's the same reason they chose LESS over Sass - React didn't have a large stable community behind it when Magento 2 was first started, I'm not sure if Angular did but either way I've heard Angular is quite complex and would seem overkill for Magento in my opinion.

Knockout is lightweight, isn't overkill and meets the requirements Magento had at the time.

There is a React based progressive web app (PWA) version of Magento which we should be able to checkout at some point this year but there is no release date as it's in an early concept stage from what I can see. For info on that see here.

1
  • 1
    Yes already following them. I had a chance to meet Ben in the Magento meet where he was also saying about PWA. So, Yes that is something Magento is serious about.
    – Gagan
    Commented Jan 16, 2018 at 9:15
8

If Magento 2 was build using react your question would be "Why doesn't it use Angular or KnockoutJs?".
If it was built using Angular....you know where this is going.

I'm not an authority on this, but I speculate it was the weapon of choice because the team was more comfortable with KOjs and it suited their needs based on their roadmap.

There was a similar debate to why choose less over sass (read more about it here: https://alankent.me/2016/05/21/magento-2-community-project-moving-from-less-to-sass/)

I also heard discussions about why ZF and not Symfony. Same thing...it's a matter of choosing the right tools suited for the job, the tools you are comfortable with.

Anyway...you are not limited too much about this choice. You can choose the tech stack, specially for frontend, that suits you best.
You may need to put in some extra effort, but you will do it only once and can reuse the results in future projects.
There are already projects out there on magento with react for example.
Here is an awesome vide from Riccardo Tempesta: https://www.youtube.com/watch?v=ElZ5UtTXpzQ
Also you can find here a proxy between react and magento: https://github.com/McFizh/magento2-react
You can find even more with a simple search online.

2
  • Actually why I asked this is because the installation step interface is using Angular, so that was the key reason for me asking it here. If they are using Angular on installation step they could have used it in place of require. Is It the only reason that knockout uses Jquery Ajax for data binding is why they have chosen. I hope you understand what I mean. Its not just the need to ask the question, but the need for magento to change different js fw for installation and different for rest of the area.
    – Gagan
    Commented Dec 21, 2017 at 11:21
  • Installer is a separate small application. Maybe it was built by a different team.
    – Marius
    Commented Dec 21, 2017 at 11:24
7

Don't know the official reason, but having used it, Knockout seems a lot more lightweight, loads the minimal necessary and suitable for integrating with Magento2 frontend templates than the heavier Angular or React.

Also the easy way RequireJS and gulp automatically blend with knockout to reduce load time and file sizes was probably important, am guessing, but fairly certain front end speed was a major consideration when planning out Magento2.

1
  • Yes speed can be a reason. Infact Magento is famous for its "SPEED" :) and if knockout is that fast that it can replace Angular it makes sense. But I am quite confident that Angular is faster, however, I am not 100% confident.
    – Gagan
    Commented Dec 21, 2017 at 11:23
4

I think a better question is, why is m2 so heavily coupled with frontend?

A lot of JS frameworks were already around when M2 released.

M2 Would have been a lot more popular if people:

  • had the choice of preprocessors, bundlers, compilers, less, sass, et al
  • had the freedom to choose which framework to use like angular1-5-n, react, vue, et al
  • had the freedom to use which ever css frameworks, bootstrap 1-4, foundation, grid, et al

Basically a lot of ET ALS. But no, they force you to use their over engineered frontend, xml driven monstrosity.

The good thing is, they have a REST API, so you can go headless and build a progressive web app.

2
  • I have found the latest magento meet I think in NL is focussed on PWA and React, so I think that's where @ben-crook is pointing
    – Gagan
    Commented Jan 16, 2018 at 9:14
  • 1
    @Gagandeep there's also this github.com/DivanteLtd/vue-storefront. I personally like frameworks that are not over engineered, and gives you more freedom on how to do things. Mostly just provide services, models and helpers. TLDR; agnostic frameworks. My personal choice of stack would be: Angular5 (n), bootstrap 4, together with sass, typescript and webpack. Commented Jan 16, 2018 at 23:59
0

Please, don't worry about it. As Anton Kril announced at the MageConf2017 -since 2.4 version Magento2 frontend will have React. And also, Redux of course, and GraphQL. But... Knockout.js will remain.

7
  • This is incorrect. Magento 2.4 will not be using React, Magento 2 will still be using the same stack (including Knockout). What you're referring to is the PWA Studio, which Magento have not announced a date for.
    – Ben Crook
    Commented Jan 3, 2018 at 12:47
  • They still force you to use a specific stack. What a bummer. Commented Jan 15, 2018 at 7:02
  • @MiguelFelipeGuillenCalo No, not really. The idea of PWA Studio is that it hooks into a new GraphQL API, which will allow you to use whatever frontend technology you would like to use and simply fetch from the server what you need. The current REST API makes this hard (because it uses a different webapi area), the new API is fit for that. PWA Studio is just their way of providing a base to those who need it. Commented Apr 1, 2018 at 8:58
  • @JisseReitsma community.magento.com/t5/Magento-DevBlog/… this clearly states what stack it will use. When they expand features, it would likely remain in that stack. Hence, they force you to use a specific stack. Commented Apr 2, 2018 at 2:49
  • @MiguelFelipeGuillenCalo I know. But it does NOT mean that the only stack you can create yourself is the one that Magento is building. Yes, if you want to have zero work and if you only want to use what Magento builds for you, then their stack is the one to use. However, your point is that "they still force you to use a specific stack" and that is not true. They build their own stack, but do not force you to use it. Instead, they build that stack on top of a GraphQL API and allow you to buid your own stack on top of that API. Much more flexibility, so you have the flexibility that you want. Commented Apr 3, 2018 at 5:56

Your Answer

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

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