Deploying a Next.js Store on Magento

Deliver a sub-second Next.js website on Magento with Layer0

Next.js is an open-source React-based isomorphic framework for server-side rendered applications. To ensure fast page loads, Next.js automatically splits code and dynamically generates the HTML every time a new request comes in with the use of a server. Key benefits of Next.js include: built-in server-side rendering (SSR), automatic code splitting, page caching and route prefetching, file-system routing, and CSS-in-JavaScript styling. 

Magento 2 is a popular eCommerce platform based on PHP7 and supports HTML5. The platform supports multiple frameworks,including the Zend Framework 1 and 2 and MySQL Percona 5.6 or greater,as well as its own proprietary frontend frameworks. The platform offers rich, out-of-the-box features, customizations and third-party integrations.

Key features which help performance include:

  • NGINX: A web server that serves as a reverse proxy, HTTP cache, and load balancer.
  • Varnish: An HTTP accelerator designed for content-heavy dynamic web pages, such as eCommerce websites on Magento 2.
  • Composer: A tool for dependency management in PHP which can allow you to reuse third-party libraries without bundling with source code and reduce extension conflicts.
  • Symfony: A PHP web application framework for controlling the content, functionality, and look and feel of your online store.
  • Redis: An open source, in-memory data structure store used as a database, cache and message broker.

Despite the above, and the fact that Magento has a built in caching module, the platform does little to help vendors in terms of site speed. In fact, the platform leaves site speed optimization to its customers and their developers / implementors.

In terms of frontends compatibility, Magento 2 offers three proprietary frontends and robust APIs. Its frontends include: Base, Luma, and PWA Studio (available for M2.3 and up) and APIs include: REST, SOAP, and GraphQL. Please note that PWA Studio and GraphQL are both only supported on Magento 2.3 or later. Furthermore, PWA Studio is geared specifically toward the platform, so you remain locked into its ecosystem. You can connect your own portable frontend or headless endpoints to the platform via the GraphQL API, however, customization of  Magento's code and/or database schema can disrupt API compatibility.  

Layer0 lets you deliver your Next.js store on Magento and enjoy sub-second speeds. While Magento 1 is no longer supported by the platform, it is still compatible with Layer0. The average website on Layer0 see median speeds of 320ms loads, as measured by Largest Contentful Paint (LCP). However, Layer0 is much more than a website accelerator. It is a Jamstack platform for eCommerce. Layer0 makes websites faster for users and simpler for frontend developers to maintain. The platform was built specifically for large-scale, database-driven websites such as eCommerce and Travel and included the following benefits: 

  • Jamstack for eCommerce via both pre and just-in-time rendering
  • Zero latency networking via prefetching of data from your product catalog APIs
  • An edge that can be configured natively in your Next.js app (CDN-as-JavaScript)
  • Edge rules that can be run locally, in pre-prod and production environments  
  • Automated, full-stack preview URLs from GitHub, GitLab, or Bitbucket with every new branch and push
  • Performant split tests at the edge for A/B tests that do not slow down the site, canary deploys, and personalization
  • Serverless JavaScript that is much easier and more reliable than AWS Lambda

With Layer0, your Next.js Magento store will run in sub-second speeds and your developers will be empowered to control edge caching and reduce rework using the various developer productivity tools that come with the platform. 

Browse around AKIRA, a Magento website on Layer0. AKIRA sped up its mobile site by 71% on Layer0, with first-page loads dropping from nearly 5 seconds to just north of 1 second, and subsequent pages loading in 500 milliseconds or less.

Layer0 is also a contributor to React Storefront (RSF), an open source eCommerce framework built on Next.js, which powers over billion dollars in eCommerce revenue a year. Try it out if you are in the process of building a modern frontend for an eCommerce site. Or if you're already using Next.js, use the this guide to deploy your Next.js application on Layer0 and get sub-second loads in as little as 1 hour of work. 

Deploy in minutes

Moovweb XDN works with all frontends
Deploy freeTakes 2 minutes