3 ms·
We're using it to build a headless Jamstack (headless CMS backend, React frontend). Next.js makes the frontend a lot nicer to work with, especially if you want
by unknown_error 5y ago
We're using it to build a headless Jamstack (headless CMS backend, React frontend).
Next.js makes the frontend a lot nicer to work with, especially if you want to deploy to a serverless config. Out of the box, it handles things like:
* Data pre-fetching (Next talks to the CMS during build instead of via a clientside request during load), then inlines the JSON response into the page so the React components have access to their initial load data (like the first page in a gallery, or the first set of blog posts) as soon as the page loads. No AJAX required. It's FAST for visitors.
* Handles page routing (like /blog/my-post or /products/24453) by mapping CMS entries into page templates
* Makes the developer experience a lot nicer, with preconfigured but extensible webpack, sass, tailwinds etc. support. Also extends the create-react-app dev server to support all the next features so you can get a good preview of how something works before you build for production
* Adds a bunch of optimizations (CSS, web fonts, tree-shaking) for faster performance
* Has optional modules you can use (authentication, ecommerce, AMP, etc.)
* It renders React + the data into straight HTML+CSS (again, fast) and that means some React components also work without Javascript enabled
Additionally, if you host on Vercel*, you get some additional features:
* Automatic image optimizations (auto-generated srcsets, webp, blurry lazy loads, etc. on the CDN)
* Incremental static regeneration: A backend server monitors the CMS for changes every X seconds, then rebuilds only the affected page (in a few seconds) instead of the whole project
* Complex rewrite rules that would normally be difficult with a static site. Not as powerful as .htaccess or Varnish rules, but good enough for simple cases
In general, the upside is that it turns React from a feature library to a more fully-featured web app framework. Still not as powerful as Angular, but hits that sweet spot where you can easily spin up a website with Next.js in a few minutes, and not have to worry about scaffolding or be overwhelmed by having to get a PhD in Angular before you can start using it.
The downside is that its primary maintainer, Vercel, also runs a hosting service. There is an inherent conflict of interest there because some Next.js are Vercel-only, and these are NOT clearly labeled in the docs. You just have to find out, upon deployment, that some features just invisibly break with no error or warning if you try to self-host or host elsewhere. Everything magically works on Vercel, but it's a crapshoot anywhere else. And it's only getting worse as they keep iterating features like next/image or Next Live but only with Vercel support.
Edit: Sorry about the formatting. I don't know what formatting engine HackerNews uses but it's awkward.