Strapi
Posted on April 24, 2023
Author: @treciaks
When selecting a framework for your web application, it is critical to consider the developer experience that they provide. Astro, Remix, and Next.js both build on top of React to provide a more streamlined experience. They both have a low learning curve, so if you're already familiar with React, you can quickly pick them up and get started.
We evaluate each to help you decide which framework is appropriate for you, not to determine which is faster or better.
Astro
Astro is a modern web framework built on React and a static site builder that requires little or no JavaScript to deliver lightning-fast, high-performance websites with a modern developer experience. It allows you to create websites using UI components from your favorite JavaScript UI frameworks such as React, Svelte, Vue, and others.
Astro websites are entirely static, with no JavaScript code whatsoever. When a component (for example, image carousels, dark and light mode) requires JavaScript code to run, Astro only loads that component and any necessary dependencies. The rest of the site is still static lightweight HTML. Check out Astro's getting started tutorial for an excellent introduction to the game.
- Astro is more flexible: you can build UI with any popular component library (React, Preact, Vue, Svelte, Solid, and others) or Astro's HTML-like component syntax, similar to HTML + JSX.
- Astro can build statically via SSG or deploy to SSR environments via adapters: Deno, Vercel serverless, Netlify serverless, and Node.js, with more to come.
Next.js
Next.js is an open-source React framework for quickly creating server-rendered React applications. It adds structure and features and handles the React tooling and configuration required for your application.
It can be used to solve common application requirements like routing, data retrieval, and integrations. Next.js was created to provide an easy-to-use development framework that would reduce the time and effort required to develop full-fledged, SSR-friendly web applications while improving the end user and developer experience. The documentation is a great place to start if you want to start with this framework.
Remix
Remix is an edge native, full-stack JavaScript framework for building modern, fast, and resilient user experiences. It unifies the client and server with web standards so you can think less about code and more about your product. (according to the official website remix.run)
Key Features
Astro
-
Zero-config: Any config explained will be handled by our
astro add
CLI command (i.e., add Svelte support withastro add svelte
). - Astro is UI-agnostic: meaning you can Bring Your Own UI Framework (BYOF).
- Easy to use: Astro’s goal is to be accessible to every web developer. Astro was designed to feel familiar and approachable regardless of skill level or experience with web development.
- Fast by default: An Astro website can load 40% faster with 90% less JavaScript than the site built with the most popular React web framework.
- Server-first: Astro leverages server-side rendering over client-side rendering as much as possible
- Content-based: Astro’s unique focus on content lets Astro make tradeoffs and deliver unmatched performance features that wouldn’t make sense for more application-focused web frameworks to implement.
- Fully-featured but flexible: Astro is an all-in-one web framework with everything you need to build a website. Astro includes a component syntax, file-based routing, asset handling, a build process, bundling, optimizations, data fetching, and more. You can build great websites without ever reaching outside of Astro’s core feature set.
Remix
- Routes: Like other frameworks, Remix allows developers to manage the different routes of their web projects using JavaScript/TypeScript files that contain handler functions. We can generate routes on our website to create files that follow the file system hierarchy of our projects, creating analog URLs for our pages. Remix routes work using the partial routing feature provided by React-Router.
- Nested components: Remix allows you to manage nested pages and components. We can create a file to handle a certain route and, at the same level in the file system, a folder with the same name. All the files we create inside that folder will be nested components of the parent route instead of different pages.
- Error Handling: Nested components bring another benefit: if an error occurs while rendering a certain component, it doesn't affect the other nested parts of the page.
- Forms: As Remix focuses on web standards, it uses native methods (POST, PUT, DELETE, PATCH) to handle forms instead of using JavaScript for that.
- Loaders and Actions: Remix provides two different types of functions to create server-side dynamic content. The loader functions handle GET HTTP requests in the server, mainly used to get data from different sources.
Next
- *Async Components & Data Fetching:* Async components are a new technique for obtaining data for server-rendered components introduced in Next.js 13. We can render async components using Promises with async and await.
- React Server Components: Server components enable us to execute and render React components on the server side, resulting in faster delivery, a smaller JavaScript bundle, and lower client-side rendering costs.
-
app/
Directory for File-Based Routing(Beta): Routes can be specified using the structure of your project directory. Simply place an entry point in thepages
directory and create a new route. - Lightning Fast Bundling: Introduced with Next.js 13 is a new JavaScript bundler, Turbopack billed as the “successor to Webpack.” Be aware that Turbopack is currently in alpha and not production ready.
- Built-in CSS and Sass support: Support for any CSS-in-JS library
- Static Exports: Next.js allows you to export a fully static site from your app using the next export command.
Hydration
Hydration is a client-side JavaScript technique for converting a static HTML page into a dynamic page. This provides a pleasant user experience by displaying a rendered component on the page but with attached event handlers. Hydration occurs before user interaction on static pages. The user experience suffers as a result.
Astro
Astro handles this through a method known as partial hydration. The method of loading individual components only when needed while leaving the remainder of the page as static HTML is known as partial hydration. Island design is critical to this process because it promotes little bits of involvement.
- Comparing Next.js vs. Astro Performance Section titled Comparing Next.js vs. Astro Performance in most cases, Astro websites will load significantly faster than Next.js websites.
- Astro automatically strips unnecessary JavaScript from the page, hydrating only the individual components that need it.
- This creates a slower page load and worse performance for your website.
Next.js
Next.js does not allow partial hydration either. There is experimental support for non-JavaScript webpages in Next.js but none for hydrating components.
- Next.js doesn't support partial hydration and instead makes the user load and rehydrate the entire page in the browser, even if most of the page content is static.
- Next.js has experimental support for fully-static, zero-JavaScript pages.
- However, the website doesn’t show support for hydrating individual components.
Remix
Remix does not support partial hydration. There are assumptions that Remix will function with the new React 18 suspense features, but Remix does not allow partial hydration.
Loading Speed
Astro
Astro is fast, basically designed for speed. The island architecture strategy aids in SEO because it ranks highly on on-site search engines. It offers a fantastic user experience and has less boilerplate code. It supports most CSS libraries and frameworks and provides a great base for style support.
Remix
Remix claims that data retrieval is sped up by loading data in parallel on the server.
Remix can prerender pages on the server because it supports server-side rendering.
In contrast to Remix, Astro provides a statically-bundled HTML file with minimal to no JavaScript.
Why the Remix rewrite is fast?
- Instead of caching documents with SSG or SWR, this version caches data at the edge in Redis.
- It runs the application at the edge too with Fly.io.
- Quick image optimization Resource Route that writes to a persistent volume.
- It's its own CDN. This might have been difficult to build a few years ago, but the server landscape has changed significantly in the past few years and is only getting better.
Why the Remix port is fast?
- Remix doesn't support SSG, so we used the HTTP stale-while-revalidate caching directive (SWR, not to be confused with Vercel's SWR client fetching package).
- The result is the same: a static document at the edge (even on the same CDN, Vercel's). The difference is how the documents get there. Instead of fetching all the data and rendering the pages to static documents at build/deploy time, the cache is primed when you get traffic.
- Documents are served from the cache and revalidated in the background for the next visitor.
Next.js
Next.js boasts of its server-side rendering and static builds features. Next.Js also includes several pre-built techniques for data retrieval.
Why Next.js is fast?
- The homepage uses Static Site Generation (SSG) with getStaticProps.
- At build time, Next.js pulls data from Shopify, renders a page to an HTML file and puts it in the public directory.
- When the site is deployed, the static file is served at the edge (out of Vercel's CDN) instead of hitting an origin server at a single location.
- When a request comes in, the CDN serves the file.
- Data loading and rendering have already been done ahead of time, so the visitor doesn't pay the download + render cost.
- The CDN is distributed globally, close to users (this is "the edge"), so requests for statically generated documents don't have to travel all the way to a single origin server.
SSR
Server-side rendering (SSR) refers to the process of pre-rendering client-side single-page applications on the server and then sending a fully rendered page on user request. Server-side rendering is essential because server-side rendered applications are SEO-friendly and fast. Apps that support server-side rendering are usually due to their reduced page load time.
Astro, Remix, and Next.js offer server-side rendering (SSR) to generate the markup and content of our pages from the web server before sending it to the client.
Ease Of Use
Next.js, Astro, and Remix have a short learning curve. Because they are all based on React, you only need a basic understanding of React to set up Next.js, Astro, and Remix. They all feature developer-friendly documentation, making them simple to use and configure.
Next includes the 'create-next-app
' CLI command for quickly launching a Next.js application. For bootstrapping an Astro application, use the 'create astro@latest
' command, whereas Remix uses the 'create-remix@latest
' command for Remix apps.
Conclusion
We looked at Astro, a highly performant library for shipping no JavaScript code, Remix, a framework for handling client-side and server-side code, and Next.js, which includes data fetching methods such as ISR, CSR, SSG, and SSR.
We looked at key features, loading speed, hydration, server-side rendering, and ease of use. This allows you to select the framework to utilize for your projects. It's not about which framework is better but which solves your problem best.
If you would like to start building with these frameworks, check out these resources:
- How to Build a Blog App with Remix and Strapi CMS
- How to Create an SSG (Static Site Generation) Application with Strapi Webhooks and NextJs
Continue discussing this topic further or connect with more people using Strapi on our Discord community. It is a great place to share your thoughts, ask questions, and participate in live discussions.
Posted on April 24, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.