Compared to React, Vue is roughly 5 years younger with nearly a quarter of the number of contributors on Github. However, Vue leads the chart with 15k and 101k more stars compared to React and Angular respectively. That speaks the extent to which the framework is meeting client needs.
While there are thousands of blogs that literally serve as a love letter to Vue JS, all of them boil down to just one factor, its size.
ReactJS weighs nearly 110 KB while AngularJS weighs around 167 KB.
VueJS framework barely weighs 18 KB!!!
Does it compromise with the performance? No. In fact, it only delivers better, especially when you are only looking for frontend development. VueJS creates a virtual DOM, much like its closest predecessor, React. The framework is expected to deliver a robust UI, leaving your visitors with an excellent User Experience.
We have already praised VueJS enough in our existing blogs. You can read one here: Vue development: what you need to know.
Back to the business. Our client was naturally attracted to VueJS for his Magento based store. All he needed was a more intuitive webstore. Inspecting through the store, we discovered the following issues that needed attention:
Slow loading speed
Not much mobile responsive
Using VueJS Template for a Faster Page Loading Speed
The existing web store was a Magento-run store, where every screen activity was controlled by the e-commerce platform. As a result, the backend possessed a strong participation every time there’s user activity. The Knockout JS-based template requested the Magento backend for the simplest of the tasks. Not to forget the buffer time for the interactions. We had to eliminate this part.
VueJS is popular for its API driven templates. A majority of the requests are resolved without reaching out to the backend services. In simple words, the backend is no more eligible to interfere in the tasks performed at the frontend. The buffer time and the cross-platform interaction time is circumvented boosting the page loading speed by numbers.
Page loading speed reduced by 5 seconds!!!
Resolving Mobile Responsiveness
Mobile focused design is the need of the hour. With VueJS, the task becomes more achievable. VueJS is described as PWA oriented technology providing the web store with the much needed mobile responsiveness. The framework allows the developers to write in any script of their choice be it Java, HTML or CSS allowing you to create and add as many frontend features, while its lightweight saves the app from getting overloaded.
Now that we have opted for a Headless approach, the template treats the database information like field details which renders the desired liquidity to the product pages at the front.
In our case, we have utilized components from VueStorefront to create the VueJS template. Its functioning is available here: Integrating Vue.JS with Magento2.
A Step-Wise Guide to Integrate Vue Storefront With Magento 2
Vue Storefront is quite fulfilling for readily establishing a storefront on any e-commerce platform. Starting with the basics, the first query developers come across is accessing data on Vue Storefront from Magento store. What we need to do first is to create a gateway to bridge the sharing of data.
Firstly, we shall allow access for Magento Integration. For the same, go to Magento2 admin panel and click on System>Integrations.
- Opt for Add new integration to request for new API.
- Next fill up the fields like Name, Password and the API permissions needed in our API like-catalog, sales, etc.
- Use these tokens to bring Magento and Vue Store to the same frame.
- Save the details and select Activate to get the OAuth access tokens. Use the tokens generated to create the bridge.
Quicker Way to Integrate Vue Storefront With Magento 2
With those permissions, the Vue-Storefront-API receives the Magento 2 data import and is managed by the Mage2vuestorefront. Being added as a dependency to the Vue-Storefront-API, Mage2vuestorefront is responsible for synchronizing the products, categories, attributes, links and more.
For importing products:
To fetch important information from the Magento 2 backend, you can run the following command:
The command fetches the details directly to the Elasticsearch instance.
Mage2vuestorefront plays as the bridge here, again.
Modify the config.js file in mage2vuestorefront directory to redirect them to your Magento 2 URL.
Moreover, add the tokens generated in the ENV files.
Let the rest of the config.js files connect with your Vue-Storefront-API Redis instances.
For importing products:
Use node cli.js commands in order to fetch the products, categories, and attributes.
The store can now fit in all the screens- desktop/tablet and mobile phones.