Chisom Kanu
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Nextjs vs Sveltekit- Which one should you use on your next project? ## Introduction Both Nextjs and SvelteKit are incredibly popular frameworks used in building web applications built with JavaScript. Both of them provide a variety of features and advantages. I'll compare them in this article to assist you in selecting the best one for your next project. ## What is Nextjs? [Nextjs](https://nextjs.org/learn/foundations/about-nextjs/what-is-nextjs) is an [open-source](https://opensource.com/resources/what-open-source) popular [JavaScript framework](https://www.tutorialspoint.com/what-is-a-javascript-framework#:~:text=What%20Is%20a%20JavaScript%20Framework%3F%20JS%20frameworks%20are,DOM%20APIs%20for%20setting%20styles%20updating%20content%2C%20etc.) for building server-side rendered ([SSR](https://www.heavy.ai/technical-glossary/server-side-rendering#:~:text=Server-side%20rendering%20%28SSR%29%20is%20an%20application%E2%80%99s%20ability%20to,sending%20a%20fully%20rendered%20page%20to%20the%20client.)) [React applications](https://reactjs.org/). It is developed and maintained by the company [vercel](https://vercel.com/). Nextjs is designed to make it easy to create fast, dynamic, and scalable web applications that deliver a seamless user experience. As a framework, Nextjs provides a simple and intuitive [API](https://www.guru99.com/what-is-api.html) that makes it easy for developers to build web applications quickly. It ensures that your website is compatible with a wide range of browsers, so you don’t have to worry about compatibility issues. Developers who have experience with React are increasingly using Nextjs. React offers a [virtual DOM ](https://www.geeksforgeeks.org/how-to-understand-by-virtual-dom/)program and server-side rendering, enhancing app speed. Additionally, it is becoming increasingly well-liked among those who require the flexibility of a hybrid architecture that combines server-side rendering (SSR) and static-site generation ([SSG](https://www.ionos.com/digitalguide/websites/website-creation/what-is-a-static-site-generator/)) in a single project. Delivering full-stack capability to the frontend is the purpose of Nextjs. Sites made with Nextjs - [Hulu](https://www.hulu.com/welcome) - [Airbnb](https://www.airbnb.com/) - [Nike](https://www.nike.com/in/) - [Hbomax](https://www.hbomax.com/geo-availability) - [Notion](https://www.notion.so/) - [Twitch](https://www.twitch.tv/) - [Target](https://targetonline.shopping/) - [Hashnode](https://hashnode.com/) - [Binance](https://www.binance.com/en) - [Tiktok](https://www.tiktok.com/) ## Features of Nextjs Here are some features of Nextjs: ### Server-side Rendering (SSR) One of the most important features of Nextjs is its ability to perform server-side rendering (SSR). This means that the [HTML](https://www.w3schools.com/html/) is generated on the server and sent to the client, providing a fast and optimized first-load experience. For example, we have a Nextjs component that returns a welcome message and a link to the "About" page. The `Link` component is used to handle navigation between pages in the application. ```javascript import Link from 'next/link'; function HomePage() { return ( <div> <h1>Welcome to Next.js!</h1> <Link href="/about"> <a>About</a> </Link> </div> ); } export default HomePage; ``` Here, the `Link` component is used to handle navigation between pages in the application. When the user clicks on the "About" link, they will be taken to the "About" page, which is defined in another Nextjs component. This allows for seamless navigation between pages in the application, while also providing the benefits of server-side renderings, such as improved load times and optimized performance. ### Automatic Code Splitting Another great feature of Nextjs is its ability to split your code into smaller chunks and only load the parts of your application that are needed. This helps keep your initial load times fast, even as your application grows in size. In the example below, we have a Nextjs component that returns information about Next.js. The `Head` component is used to set the title of the page for better SEO. ```javascript import Head from 'next/head'; function AboutPage() { return ( <div> <Head> <title>About | Next.js Example</title> </Head> <h1>About Next.js</h1> <p>Next.js is a popular React-based JavaScript framework.</p> </div> ); } export default AboutPage ``` The `Head` component is used to set the title of the page, which is an important aspect of search engine optimization (SEO). Using the Head component, we can ensure that the page's title is set correctly, even when the page is dynamically generated on the server. ### Static File Serving Nextjs also makes it easy to serve static files, such as images, fonts, and stylesheets. You can simply place your static files in a `public` directory at the root of your project and they will be available to be served by Nextjs. In the code below, we have a Nextjs component that displays a welcome message and an image of the Nextjs logo. The `styles` module is used to set the styling of the page. ```javascript import styles from '../styles/Home.module.css'; function Home ``` ## What is Sveltekit? [SvelteKit](https://kit.svelte.dev/) is a new framework from the creators of the popular JavaScript library Svelte, aimed at making it easier for developers to build web applications with a modern and efficient approach. SvelteKit is built on top of Svelte and provides a comprehensive suite of tools and features for building, deploying, and scaling web applications. It is known for its approach to building web applications by compiling components to highly optimized JavaScript code during the build process, making it faster and more efficient than other frameworks that rely on runtime computations. SvelteKit takes this one step further by providing a complete end-to-end solution for building and deploying web applications. In addition, it allows you to focus on building and refining your web applications, without having to worry about underlying infrastructure or deployment process. Sites made with SvelteKit - [Svelte.dev](https://svelte.dev/) - nytimes.com - daisyui.com ## Features of SvelteKit SvelteKit offers a wide range of features. Here are some features of SvelteKit: ### Easy setup SvelteKit makes getting started with a new project incredibly simple. With just a few commands, you can create a new project and have a working application up and running in no time. ``` npx @sveltejs/kit init my-app cd my-app npm run dev ``` The first command creates a new SvelteKit project named "my-app". The second command changes to the project directory, and the third command starts a local development server. ### Component-based architecture SvelteKit follows a component-based architecture, where each piece of UI is represented as a self-contained component. This makes it easy to manage and maintain your application and enables you to reuse components across your application. ```javascript <script> let name = "World"; </script> <h1>Hello {name}!</h1> ``` We define a component that displays a greeting to the user. The component has a single property called `name` that can be used to customize the greeting. The `name` property is set to "World" by default, but it can be overridden by passing a new value to the component. ### Server-side rendering SvelteKit provides built-in server-side rendering, making it easy to generate HTML on the server and deliver it to the client. This results in faster initial load times and better [SEO](https://moz.com/learn/seo/what-is-seo). ```javascript <script context="module"> export async function load({ page }) { const res = await fetch(`https://api.example.com/posts/${page.params.slug}`); const post = await res.json(); return { props: { post } }; } </script> <script> export let post; </script> <h1>{post.title}</h1> <p>{post.content}</p> ``` Here, we define a SvelteKit page that displays a blog post. The load function is used to fetch the blog post from an API and pass it as a prop to the page. The page is rendered on the server and sent to the client as HTML. ### Static site generation SvelteKit also supports static site generation, allowing you to build fast, lightweight, and scalable websites that can be easily hosted and served from a [CDN](https://www.cloudflare.com/learning/cdn/what-is-a-cdn/). ``` npm run build npm run export ``` The first command builds your SvelteKit application for production. The second command exports your application as a set of static files that can be easily hosted and served from a CDN. ### Routing Another important feature of SvelteKit is its powerful routing system. With SvelteKit, you can easily define routes for your application, and the framework will automatically handle the navigation between different pages. Here's an example of how to define routes in SvelteKit: ```javascript <svelte:head> <title>My App</title> </svelte:head> <nav> <a href="/" class:active={segment === ''}>Home</a> <a href="/about" class:active={segment === 'about'}>About</a> <a href="/contact" class:active={segment === 'contact'}>Contact</a> </nav> <main> <svelte:component this={segment} /> </main> <script> import Home from './routes/Home.svelte'; import About from './routes/About.svelte'; import Contact from './routes/Contact.svelte'; const routes = { '': Home, 'about': About, 'contact': Contact }; export default { components: routes, preload({ query }) { return { segment: query.s }; } }; </script> ``` In the example above, the `routes` object maps the [URL](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/What_is_a_URL) segments to components. The `segment` is passed to the `preload` function, which is executed on the server, and the value is then available in the component. The `main` section then uses the `segment` to determine which component to render. ## Comparing Nextjs and Sveltekit In this section, I will give brief similarities and differences between the two frameworks. ## Similarities: Nextjs and SvelteKit have built-in support for server-side rendering, which allows for better performance, improved SEO, and a more seamless user experience. They provide a straightforward way to define and handle routing in your application. Both Nextjs and SvelteKit follow a [component-based architecture](https://www.tutorialspoint.com/software_architecture_design/component_based_architecture.htm), which makes it easy to maintain and structure your codebase. In addition, both frameworks have a modern development experience, with features like hot-reloading, easy build, and deployment. They aim to deliver a fast and responsive user experience. ## Differences: Here are some differences between Nextjs and SvelteKit. ### Tooling: Nextjs and SvelteKit differ in their [tooling](https://www.goodfirms.co/glossary/software-tools/), Nextjs is part of the React ecosystem, which means that it has a rich set of tools and libraries that you can use to build your applications. This includes tools like Create React App, React DevTools, and a large number of plugins for popular code editors like [Visual Studio Code](https://code.visualstudio.com/). SvelteKit, on the other hand, is a relatively new framework and has a smaller set of tools and libraries available. The Svelte community is growing quickly and new tools are being developed. ### Architecture Nextjs is a server-side rendered (SSR) framework built on top of React. This means that Next.js generates the HTML for your application on the server and sends it down to the browser, where JavaScript takes over and makes the page dynamic. This approach can improve the performance and SEO of your application, as the initial load time is faster and search engines can easily index the content. Here's an example of a component in Nextjs: ```javascript import React from 'react'; function HomePage() { return <h1>Hello, Next.js!</h1>; } export default HomePage; ``` SvelteKit, on the other hand, is a client-side framework built on top of the Svelte library. SvelteKit generates the JavaScript for your application on the client, and the page is fully rendered in the browser. This approach is generally faster and more efficient than SSR, as the JavaScript only needs to be downloaded once and can be reused across multiple pages. And here's an equivalent component in SvelteKit: ```htmlmixed <h1>Hello, SvelteKit!</h1> ``` ### Routing Another key difference between Nextjs and SvelteKit is their approach to [routing](https://divpusher.com/glossary/routing/#:~:text=Routing%20or%20router%20in%20web%20development%20is%20a,subpage%2C%20it%20will%20display%20a%20Hello%20World%20text.). Nextjs has built-in support for client-side routing, which allows you to navigate between different pages in your application without reloading the entire page. This is done using the `Link` component and the `useRouter` hook. Here's an example of routing in Nextjs: ```javascript import React from 'react'; import Link from 'next/link'; function HomePage() { return ( <> <h1>Hello, Next.js!</h1> <Link href="/about"> <a>About</a> </Link> </> ); } export default HomePage; ``` SvelteKit, requires you to set up client-side routing yourself. This can be done using a library such as `svelte-routing`, but it does require some additional setup. And here's an example in SvelteKit: ```javascript <script> import { Link, navigate } from 'svelte-routing'; </script> <h1>Hello, Sveltekit!</h1> <Link to="/about">About</Link> ``` ### State management [State management](https://www.techtarget.com/searchapparchitecture/definition/state-management) is another area where Nextjs and SvelteKit differ. Nextjs uses the React framework, which means that you have access to all of the popular state management tools and libraries, such as [Redux](https://redux.js.org/) and [MobX](https://mobx.js.org/README.html). Here's an example of managing state in Nextjs using the `useState` hook: ```javascript import React, { useState } from 'react'; function HomePage() { const [count, setCount] = useState(0); return ( <> <h1>Hello, Next.js!</h1> <p>Count: {count}</p> <button onClick={() => setCount(count + 1)}>Increment</button> </> ); } export default HomePage; ``` SvelteKit, does not have a built-in state management solution. Instead, you can use the [Svelte store](https://developer.mozilla.org/en-US/docs/learn/tools_and_testing/client-side_javascript_frameworks/svelte_stores) to manage the state, or you can use a third-party library such as [XState](https://xstate.js.org/docs/) or [Recoil](https://recoiljs.org/). Here's an example in SvelteKit: ```javascript <script> let count = 0; function increment() { count += 1; } </script> <h1>Hello, Sveltekit!</h1> <p>Count: {count}</p> <button on:click={increment}>Increment</button> ``` Here is a table comparing Nextjs and SvelteKit: | Features | Nextjs | SvelteKit | | --------------------------- | ------------------------------------------------------------------- | ------------------------------------------------------------- | | Framework | React based | Svelte based | | Language | JavaScript | JavaScript | | Routing | Built-in with good customization options | External library needed, offers limited customization options | | Tooling | Large ecosystem | Growing ecosystem | | Learning curve | Steep for new React users | Shallow for those familiar with Svelte | | Server-side rendering (SSR) | Built-in, supports automatic (SSR) and Static site generation (SSG) | Built-in, supports automatic SSR | | Library size | Larger | Smaller | | Code splitting | Built-in and automatic | External library needed, manual code splitting | | Community support | large and active | Growing, but smaller than Nextjs | ## Which one should you use on your next project? Nextjs is a good choice if you want a complete, all-in-one solution for building a web application that can handle both server-side and client-side rendering, and if you have a complex application with dynamic data and a lot of user interactions, it has a rich ecosystem of plugins and integrations with other technologies. Nextjs also provides a suite of features for building performant and scalable web applications, including automatic code splitting, optimized performance and improved SEO. On the other hand, SvelteKit is a good choice if you want to build scalable and cost-effective application with low operational overhead, and if your application has a lot of independent, small tasks that can be broken down into seperate functions. It allows you to write your application logic as a small, single-purpose function that can be easily deployed and run on a serverless application. In addition, the choice between Nextjs and SvelteKit depends on your specific needs and requirement for your project. If you have a cpmplex, data-driven web application, Nextjs is probably a better choice, while SvelteKit is better suited for smaller, independent task. ## Conclusion Nextjs and SvelteKit are both popular frameworks for building applications. The choice between between nextjs and SvelteKit will depend on your personal preference and the needs of your project, but both frameworks are definitely worth considering for your next project.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully