Sub topic 18
When to use Vite and when to use a framework
This chapter assumes you can scaffold a Vite project, read its files, and run npm run build. It covers where a Vite single-page app fits among other ways to start a React project, and how to choose.
What a Vite app gives you
A Vite React app is a single-page application (SPA). The browser downloads one index.html and a JavaScript bundle. React then renders every screen in the browser, on the client.
Vite supplies the dev server, the build, and the React plugin. It does not supply routing, data loading, or server rendering. If you need those, you add libraries or pick a framework that includes them.
What frameworks add
A React framework builds on React and adds features that a plain Vite SPA lacks.
- Routing from the file system. Files in a folder become pages.
- Server rendering. HTML is produced on a server, so the first paint shows content and search engines can read it.
- Data loading. The framework fetches data before or during rendering.
- Deployment adapters. The framework builds for specific hosts.
Common choices include Next.js and React Router in framework mode. Check each project's documentation for its current features and setup commands, because they change often.
Comparing the options
| Need | Vite SPA | Framework |
|---|---|---|
| Learning React itself | Good fit | More concepts to learn |
| Internal dashboard behind a login | Good fit | Works, often more than needed |
| Public pages that must rank in search | Weak fit | Good fit |
| Fast first load on slow networks | Weaker, since the bundle must load first | Stronger with server rendering |
| Full control over tooling | Yes | Framework decides many things |
| Hosting | Any static host | Often needs a server or an adapter |
Making the decision
A Vite SPA is a sensible default in these cases:
- You are learning React and want few moving parts.
- The app sits behind a login, so search ranking does not matter.
- You want to host static files on any provider.
- You prefer to choose your own router and data library.
Pick a framework when the first page load and search visibility matter, or when you want routing and data loading to come as one tested package.
Adding what Vite lacks
If you stay with Vite, add pieces as the app needs them.
npm install react-router-domThis installs a client-side router. You then define routes yourself, instead of the framework deriving them from files. Libraries for data fetching are installed the same way.
Exercise
You are building a public blog that must appear in search results and load quickly on slow phones. Would you start with a Vite SPA or a framework? Give two reasons.
Show answer
A framework. First, server rendering sends ready-made HTML, so search engines can read the content and the first paint is quick. Second, built-in routing and data loading save you from assembling and maintaining them yourself. A Vite SPA must download and run its JavaScript before any content appears.
Exercise
Your team is building an admin dashboard behind a login, hosted on a plain static file host. Which starting point fits, and why?
Show answer
A Vite SPA. Search ranking does not matter behind a login, and the build output in dist is static files that any static host can serve. You can add a router and a data library as needed.