Urgent.News

What's breaking now, across thousands of outlets.

Tech

Sanity website slow? How to find the cause and what a fix costs

If your Sanity website is slow, the instinct is to blame the CMS. On the Next.js sites I get asked to look at, Sanity is almost never the bottleneck. The slowness comes from how the frontend asks for content, caches it, and ships it to the browser. This post is a diagnosis guide. It lists the five causes I see most, how to tell which one you have using tools you already own, and what a fix…

If your Sanity website is running slowly, there's a good chance the problem lies in the way front-end code requests and displays content. To diagnose this issue, it's essential to understand where the delay occurs: server time, asset weight, or browser work. Focus on three primary causes of slowness and their corresponding solutions.

First, GROQ waterfalls often lead to high TTFB (time to first byte) on pages featuring related content, such as posts with an author, category, and related posts. To identify this issue, log the timing around each fetch or look for several awaits in a row within the page component. The recommended fix involves modifying the GROQ query to resolve references in a single query.

Second, uncached fetches can cause every page view to be slow, and high API usage may indicate this problem. Confirm an uncached fetch by checking if the route is rendered dynamically on every request. Typical triggers include reading cookies or headers in a shared layout, leaving draft-mode logic active for all visitors, or fetching without any cache strategy. The solution is to decide per route what can be cached, tag fetches by document type, and revalidate from a Sanity webhook to ensure editors see changes quickly.

Third, oversized or unmanaged images can degrade performance. High TTFB indicates the server is functioning correctly, but poor LCP (largest contentful paint) may suggest oversized images. Confirm this by checking network tabs for image sizes and dimensions. The fix includes using real width, height, and sizes in next/image, utilizing Sanity's image metadata instead of guessing, and prioritizing only the true hero image.

Fourth, client-side rendering may be unnecessary for some pages, leading to poor INP (interactive visual stability) and large JavaScript transfers, especially on mobile devices. Look for the presence of client-side rendering components and verify if real text appears in the source code. If client components are required for interactive elements like filters or menus, reserve them for such purposes and keep the main content in server components.

Lastly, bloated JavaScript bundles can also contribute to slowdowns. Large client chunks and dependencies in client components can negatively impact INP. Confirm this by analyzing the Next.js bundle and identifying unnecessary dependencies. Solutions involve analyzing and cutting down on Next.js chunk bloat, as well as lazy-loading Portable Text renderers.

In conclusion, most slow Sanity websites have two or three of these issues at once. Addressing them can lead to improved conversion rates, better search engine rankings, and reduced hosting costs. To tackle the problem, measure performance using field data and lab traces, then apply the appropriate fixes for the specific cause identified.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

I got tired of tracking backlink prospects in a spreadsheet

I have shipped a lot of small sites. The part that never got easier was the week after launch, when the product worked and almost nobody could find it. Content helps. So does a clear page title.

  • Developed LinkTRX to streamline backlink prospecting
  • Users unlock records by completing tasks, earn credits
  • Chrome extension and daily free record enhance usability

Field Card: a printed page that gets me off the screen

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 1: Touch Grass What I Built Going for a walk sounds simple until you are standing outside with no plan and a phone in your…

  • Field Card is a web app for planning outdoor activities
  • User inputs location, duration, area type, and group size
  • Printed card removes phone distraction during outing

More from Saturday 17 October →