10 best practices to improve your NextJS application on Cursor

tl;dr If you’re not a professional NextJS developer for a very long time, the blog will help you with some low hanging fruits that can improve your app’s performance significantly. I’ve tried to add Cursor prompts, step-by-step instructions and screenshots wherever I could. If you face any issues or need help, please feel free to bug me on discord.

Stack Assumption: Next.js + Supabase + Cursor (or similar AI coding assistant)


1. ✨ Speed Up Your Pages (Next.js)

Why It Matters:

Faster pages = better user experience, lower bounce rates, and higher conversions.

What You Should Do:

Speed up your pages

Prompt to Use with AI:

"Convert this page to use getStaticProps or getStaticPaths for better caching."

Code Example:

import dynamic from "next/dynamic";
const HeavyComponent = dynamic(() => import("../components/HeavyComponent"));

export async function getStaticProps() {
  const data = await fetchData();
  return { props: { data }, revalidate: 60 };
}

2. πŸ” Real-Time Error Tracking

Why It Matters:

Catching issues early = faster debugging, less downtime, and better user trust.

What You Should Do:

Real-Time Error Tracking

Prompt to Use:

"Add Sentry or @hyperlook/telemetry-sdk to track frontend and backend errors."

Code Snippet:

import * as Sentry from '@sentry/nextjs';
Sentry.init({ dsn: process.env.SENTRY_DSN });


3. πŸ‘› Shrink Bundle Size

Why It Matters:

Smaller bundles = faster load times and better first interaction.

What You Should Do:

Prompt:

"Visualize my bundle size and identify bloated dependencies using @next/bundle-analyzer"

Shrink Bundle Size

Code Tip:

import debounce from 'lodash/debounce';

4. ⚑ Boost Dev Speed

Why It Matters:

Clean, consistent code improves team velocity and reduces bugs.

What You Should Do:

Prompt:

"Set up Prettier, ESLint, and Husky pre-commit hooks."


5. πŸ”„ Snappy APIs with SWR

Why It Matters:

Caching and background revalidation make your UI feel instant and responsive.

What You Should Do:

Prompt:

"Convert this API fetch to use SWR/react-query/RTK Query with caching and revalidation."

SWR Comparison

view the full comparison here.

Code Example:

import useSWR from 'swr';
const fetcher = url => fetch(url).then(res => res.json());
const { data } = useSWR('/api/user', fetcher);


6. πŸ”’ Secure Your Application

Why It Matters:

Security issues break user trust and can have legal/financial consequences.

What You Should Do:


7. πŸ” SEO Optimizations

Why It Matters:

More traffic from search engines = higher growth, especially for public-facing pages.

What You Should Do:

Prompt:

"Generate sitemap and improve HTML structure for SEO."

Lighthouse SEO


8. πŸ“‚ Supabase Best Practices

Why It Matters:

Bad practices can leak sensitive data or crash your app at scale.

What You Should Do:


9. πŸ›‘οΈ RLS (Row Level Security) Done Right

Why It Matters:

Data should only be accessible to the people who own it. RLS makes that possible.

What You Should Do:

RLS Policy

An example of how a RLS policy looks like in supabase, these functions can be defined as well here

Supabase Functions

How to Do It:

Open Supabase SQL Editor and enter:

"Add an RLS policy to ensure users can only see their own todos."

"Fix this query with joins so it passes all relevant RLS policies."


10. 🧰 Build Awareness: Test Like a User

Why It Matters:

Developers miss bugs that only appear in real-world conditions.

What You Should Do:

Network throttle

How you can verify how your website looks like in various devices

Device Toolbar

Note:

Cursor or AI tools can’t run Lighthouse audits or simulate mobile networks β€” you must do this manually in the browser.


If you liked the blog and have any thoughts, let me know!