Next.js 9.5 added redirects for sending requests to another path or website, with path and wildcard matching. Robinson uses leerob.io/youtube as an example of an external redirect. Rewrites proxy requests to another destination while keeping the original URL visible, which can help when incrementally moving a site to Next.js.
10 Next.js Tips You Might Not Know!
Lee Robinson, a software developer at leerob, shares 10 lesser-known Next.js tips in a video on the leerob channel.
Preview mode lets editors view draft content from a headless CMS on a statically generated site through a unique preview URL. Robinson also shows how to hook a Node script into the build process to generate a sitemap, RSS feed, or search index.
Robinson describes swapping React for Preact in the client production build to reduce shipped JavaScript, while cautioning that compatibility with newer React features may vary. He also recommends absolute imports and module aliases configured in jsconfig.json or a TypeScript config to simplify import paths.
A single Next.js API route can handle different HTTP methods: his views example increments a count on POST and returns it on GET. He also demonstrates setting Cache-Control headers, which can let a client receive a 304 not modified response. Page components can expose title and description properties for a shared layout in _app.js.
Robinson highlights Capacitor.js, created by Ionic's creator, as a way to build mobile-like experiences with Next.js. The example combines Next.js and Tailwind and includes hot module reloading, modals, swipe-to-close, and virtual lists.
Takeaways
- Use redirects for visible URL changes and rewrites to proxy requests while preserving the URL.
- Preview mode can make draft content reviewable even when a site is statically generated.
- Build hooks can automate tasks such as sitemap generation and search indexing.
- Evaluate Preact against your app's React feature needs and measure the client bundle before adopting it.
- Handle related HTTP methods in one API route and use cache headers when responses can be reused.
Mentioned in this talk
Search inside this talk
What was claimed 4
- feature
Next.js: Built-in redirects and rewrites were added in Next.js 9.5.
“After Next.js 9.5, redirects were added directly into the framework”
YouTube Unverified1 source· Talk
- feature
Next.js: Preview mode lets users view draft content in a statically generated site.
“Preview mode solves that by letting you see a statically generated version of the draft content.”
YouTube Unverified1 source· Talk
- uses
“You can swap out React with Preact very easily in Next.js.”
YouTube Unverified1 source· Talk
- featureCapacitor.js: Supports native-like app experiences, including hot module reloading with Next.js.
“You can do things like hot module reloading with Next.js and still get a native-like experience with your app.”
YouTube Unverified1 source· Talk
Related talks
18:46
1:04:54
1:21:37
50:44
1:20:10
1:57:48
