Next.js with MOXY
Tags: react, nextjs, web
Published: 2020-10-15 11:14:40

## Some context

At MOXY we aim for a balance between impact, excellence and pragmatism. This has even brought us the Awwwards **Mobile Site of Year** prize [for our own website](https://moxy.studio), which is evaluated by a Google jury.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/xtu2111wkc91fjci8nv2.png)
<figure>
  <figcaption>https://moxy.studio</figcaption>
</figure>


To achieve this sort of result, our designers and engineers work together from day 1 to deliver a balanced outcome given the project constraints, be it time or budget. This close collaboration between people with different expertise allows everyone to give input early on, often resulting in better ideas and solutions. We’ve combined this into a process that we call **Engineered Design** (we might talk about this in a future article).

A clear process is key, but we also needed the right tech foundations, and that’s why I’m writing this article, to talk about our web boilerplate, the challenges it solves, and **how that improves Developer Experience**, and **ultimately the User Experience**.

---

## The challenge

There’s a lot of frontend craftsmanship involved in projects of this level, especially on making everything work smoothly while keeping the project maintainable. That’s why we use and love [React](https://reactjs.org/), one of the most popular libraries to build user interfaces.

But React is just a view layer. Every time we wanted to start a project, we were dedicating a lot of time laying down the foundations. The process was repetitive, error-prone and tedious. That time would be definitively better spent on the actual website implementation.


## Our first attempt

To reduce the time it takes to setup a project, we created [React with MOXY](https://github.com/moxystudio/react-with-moxy/), an open-source boilerplate that packaged React, React Router and modern JavaScript tooling such as ESLint, Stylelint, Webpack, Babel, PostCSS and Jest. It even had support for [server-side rendering](https://en.wikipedia.org/wiki/Isomorphic_JavaScript), which is very challenging and complex to get it right, but more on that later.

Our engineers would copy this project and would have a barebones website working in minutes.

[**moxystudio/react-with-moxy**](https://github.com/moxystudio/react-with-moxy)
*MOXY’s boilerplate to create isomorphic react applications.*

Many websites were successfully built with it, but it was hard to keep up with the speed in which these libraries release new versions. The maintenance burden was increasing as months passed by to the point it became unsustainable.
> # MOXY advocates for open-source and its philosophy. If something can be reused, then we create a package. And if that package is not critical for our business, then we make it open-source.

After three years of existence, MOXY has a vast catalogue of [open-source packages](https://github.com/moxystudio), and [some](https://www.npmjs.com/package/cross-spawn) of [them](https://www.npmjs.com/package/proper-lockfile) have millions of downloads each month. We’re also consumers of open-source and we continuously monitor what’s being released in the wild.

One of the open-source projects that caught our attention was [Next.js](https://nextjs.org/), by Vercel (previously Zeit). We immediately saw its potential, and once it caught up with the features we needed, we ditched React with MOXY for Next.js. It was a humble step to replace a project we created with one made by another company, but I’m glad we did it.

Fun fact: Next.js [uses](https://github.com/vercel/next.js/blob/53a3ffea25a21847ea1882dcd08ab1634f5b2af7/package.json#L70) [cross-spawn](https://github.com/moxystudio/node-cross-spawn) ️❤️, one of MOXY’s most popular open-source projects with **~37.000.000 weekly downloads** as of this date 😲.


## Next.js matured

Next.js is the React framework that everyone was missing. It has a vast feature set, is well supported and maintained, and has a huge community.

One of its core features is [Server-side Rendering](https://nextjs.org/docs/basic-features/pages#server-side-rendering) (SSR). SSR is a technique that allows you to serve an initial payload with HTML, JavaScript, CSS, and application state. JavaScript running on the client picks up the rendered HTML and resumes its normal operation. This approach has many benefits, but the primary ones are:

* Consistent SEO, as the crawlers will see fully rendered pages just like traditional static web pages.

* Functional Social Sharing, as we can add social meta tags specific for each page. Social networks will be able to correctly show a preview card for all pages.

* Faster [First Contentful Paint](https://web.dev/first-contentful-paint/) (FCP), as the browser doesn’t need to wait for JavaScript to display content. This improves the perceived performance, that is, how fast a website seems to visitors.

Another core feature is [Static Generation](https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation) (SG). As opposed to SSR, where the server renders pages on every new request, with SG, pages are rendered at build-time. When a request arrives to the server, the page is already rendered and is sent to the client right away. Pre-rendered pages can also be cached by [CDNs ](https://en.wikipedia.org/wiki/Content_delivery_network)to further boost performance. The major disadvantage of SG, however, is when you need to update content. It’s very frustrating to change an article in a [CMS](https://en.wikipedia.org/wiki/Headless_content_management_system) and having to wait several minutes for the change to be shown on the live website. And for websites that have hundreds of thousands of pages, it’s just too slow to be viable. Next.js v9.4 introduced [Incremental Static Regeneration](https://nextjs.org/blog/next-9-4#incremental-static-regeneration-beta) (ISG) under beta, where static pages are updated behind the scenes as traffic comes in. This technique retains the benefits of SG while solving its shortcomings regarding updates.

But what’s awesome is that Next.js allows us to combine SSR with SG and ISG, allowing pages to be partially static and partially dynamic!


## A new boilerplate is born

After embracing Next.js, we decided to create a new boilerplate, [Next.js with MOXY](https://github.com/moxystudio/next-with-moxy), which is also open-source. All the code and libraries that were in our previous boilerplate were removed as they are all being abstracted by Next.js. The maintenance burden was gone and we had more time to dedicate to our clients’ projects.

All websites we make have a base set of features:

* **Internationalization** (i18n): Multi-language support is added from the start, even if the project doesn’t initially require it. Uses [React Intl](https://formatjs.io/docs/react-intl/) and [@moxy/next-intl](https://github.com/moxystudio/next-intl).

* **Page transitions:** Orchestrates exit and enter transitions between routes, includes support to add customized visual effects to such transitions and restores the scroll position automatically. Powered by [@moxy/react-page-swapper](https://github.com/moxystudio/react-page-swapper) and [@moxy/next-scroll-behavior](https://github.com/moxystudio/next-scroll-behavior).

![Page transitions on Audio UX, one of our most recent projects.]
(https://dev-to-uploads.s3.amazonaws.com/i/kihbeww73tcxhav61bd6.gif)
<figure>
  <figcaption>Page transitions on Audio UX, one of our most recent projects.</figcaption>
</figure>

* **Accessibility** (a11y): Care for accessibility, by using semantic HTML, and paying attention to keyboard interactions or alternative input and output devices. Automatic checks are in place to enforce good practices on accessibility.

* **SEO**: Any top-level pages will have dedicated metatags which integrate with search engines and social media scrapers.

* **Analytics:** Usage of [Google Tag Manager](https://marketingplatform.google.com/about/tag-manager/) to easily add analytics to the projects, like page views or track interactions. Analytics are only enabled after we have consent from the visitor, to comply with GDPR and similar legislation.

* **Code linting**: Usage of [ESLint](https://eslint.org/) and [Stylelint](https://stylelint.io/) to ensure code is consistent across the codebase.

* **Unit testing**: Automated tests to validate the correctness and to provide confidence upon code changes, using [Jest](https://jestjs.io/).

* **Docker**: A Dockerfile to package the website into a [Docker](https://www.docker.com/) image that can run anywhere, on the cloud or on-premises.

* **Changelog generation:** A changelog file adhering to the [Conventional Commits specification](https://www.conventionalcommits.org/) is automatically generated and kept up to date on each release.

* **Staging pipeline**: A CI/CD pipeline that automatically runs tests and deploys the website to a staging environment, with support for pull requests.

* **Documentation**: A webpage with key documentation, including instructions on how to set it up and how to deploy it.

![Documentation for Next.js with MOXY.]
(https://dev-to-uploads.s3.amazonaws.com/i/jau5svrrjs0udy253qtb.png)
<figure>
  <figcaption>Documentation for Next.js with MOXY.</figcaption>
</figure>

We have embedded all these features, and a few more, into our boilerplate. Moreover, we have an optional set of recipes that can be followed to easily add other features. Two examples are recipes to integrate with [Contentful](https://next-with.moxy.tech/docs/recipes/contentful) and [DatoCMS](https://next-with.moxy.tech/docs/recipes/dato-cms), two of the leading headless CMS on the market.

You may visit the project’s website at [https://next-with.moxy.tech](https://next-with.moxy.tech/). Feel free to use it, give feedback and contribute! 🙏

![Next.js with MOXY logo]
(https://dev-to-uploads.s3.amazonaws.com/i/ud6hh6wk0ak6ck6kqptw.png)
<figure>
  <figcaption>Next.js with MOXY logo</figcaption>
</figure>


## Wrapping up

With [Next.js](https://nextjs.org/) and [Next.js with MOXY](https://next-with.moxy.tech/), our team has an efficient way to kickstart a project with features that meet our base offering. Recipes can be followed to progressively add other features, such as creating a simple REST API or integrating with a CMS.

The developer experience is consistent across projects that are using it, and our engineers are able to switch projects easier than ever. We’re now able to deliver faster and with a higher degree of polishing, two things highly appreciated by our clients.

Below a quick peek on the most recent projects we’ve built using [Next.js with MOXY](https://next-with.moxy.tech/):

**Audio UX — [https://auxnyc.com](https://auxnyc.com/)**
> A full-service audio branding agency specializing in audio logos, UX sound design, automotive sound design, audio for voice experiences, and more.

![Audio UX]
(https://dev-to-uploads.s3.amazonaws.com/i/ngkvfak3elrsimz1l88m.png)

**Dashdash — [https://dashdash.com](https://dashdash.com)**
> Do more with your spreadsheets. Build powerful [sales](https://dashdash.com/sales) and [marketing](https://dashdash.com/marketing) tools. Publish them as web apps. All in one tool, without code.

![Dashdash]
(https://dev-to-uploads.s3.amazonaws.com/i/y8tl4hbejegsw83gg2ej.png)

**THU Japan — [https://japan.trojan-unicorn.com](https://japan.trojan-unicorn.com)**
> THU is a strong community with a powerful bond. THU Japan is a Storytelling Bootcamp event taking place in the city of Kaga, Japan in 2020.

![THU Japan]
(https://dev-to-uploads.s3.amazonaws.com/i/hpfxq5fxe83ov2pr6l26.gif)


---


At MOXY, we build websites and applications that our customers can feel proud of, instead of being embarrassed and frustrated. Our Engineered Design process helps our customers have a deeper understanding of their challenges, and provides a clear path for solving them through careful design and implementation.

**Looking for help with a project? [Tell us a bit more](https://moxy.studio/contacts).**

*Written by* André Cruz