After three months of rapid development, experimenting and iterating, we had added 20 new features. But this also left us with technical debt: a heavier project. Because our app runs in a WebView, performance was more disappointing than in a regular browser. After seeing harsh reviews on the App Store, I realized we couldn’t put it off any longer and started putting our code on a diet.

1. Diagnosis: Reading the LCP Breakdown
First, I checked the current state with Chrome Lighthouse.


Both LCP and CLS needed improvement.
LCP isn’t just a number saying “the screen is slow.” It can be broken down into four stages showing where the time goes.
| Stage | Meaning |
|---|---|
| TTFB | Time from the request until the first byte arrives from the server |
| Resource load delay | Time from TTFB until the browser starts requesting the LCP resource |
| Resource load duration | Time spent actually downloading the LCP resource |
| Element render delay | Time from finishing the resource load until rendering it on screen |

Time to first byte (TTFB): 137ms (41.6%)
Resource load delay: 102ms (30.8%)
Element render delay: 91ms (27.6%)
Resource load duration: 0.1ms (0.0%)
What stands out is that resource load duration is 0.1ms. Downloading the image itself is almost instantaneous, but starting the request takes a full 102ms.
I checked the LCP element: it was a carousel thumbnail image.

→ The key was to request the image earlier, rather than download it faster.
2. Image Optimization
Without the loading attribute, the browser requests all images when entering the page, including those outside the viewport. If these images occupy the network first, the LCP image’s request gets pushed back. That was why resource load delay was so long.
// Before: all images load immediately
<img src={imageUrl} alt={alt} />
// After: load only when entering the viewport
<img
src={imageUrl}
alt={alt}
loading="lazy"
fetchPriority="low"
/>
I added loading="lazy" and fetchPriority="low" to home carousel images that aren’t visible on the first screen.

3. Dynamic Imports
How bundlers handle imports
Here’s the home page build output before optimization.
ƒ / 20.9 kB 338 kB
The root layout statically imported the login modal, promotion modal, and others.
// Before: all modals are included in the initial bundle
<div className={cn(responsive.container, 'relative')}>
{children}
<LoginModal />
<ShopAtpisodeLoginModal />
<PromotionTermsModal />
</div>
<SonnerToaster />
<ChristmasGiftModalProvider />
At build time, webpack statically analyzes import statements and groups connected modules into a chunk. Statically imported modals go into the home chunk whether they’re visible or not.
With dynamic(), the bundler separates the module into its own chunk and requests it when the component actually renders.
What ssr: false does
Using a dynamic import without ssr: false still makes the server attempt to render the component. Rendering components such as modals during SSR adds little value when they aren’t needed in the initial HTML, and adds a comparison between server HTML and client output during hydration.
Setting ssr: false skips SSR entirely and mounts the component only on the client.
// After: load only when needed
const SonnerToaster = dynamic(() => import('@/providers/SonnerProvider'), {
ssr: false,
});
const LoginModal = dynamic(() => import('@/components/modals/login-modal'), {
ssr: false,
});
const ShopAtpisodeLoginModal = dynamic(
() => import('@/components/modals/shop-atpisode-login-modal'),
{ ssr: false },
);
const PromotionTermsModal = dynamic(
() => import('@/components/modals/promotion-terms.modal'),
{ ssr: false },
);
Before: ƒ / 20.9 kB 338 kB
After: ƒ / 18.5 kB 337 kB
The page size fell by 2.4KB, but first load went from 338KB to 337KB: only a 1KB reduction. The modal chunks still get downloaded. The difference is timing. JavaScript needed for the initial render executes first, and modal chunks load when actually needed.
Changes in TBT: the dynamic import trade-off
After applying dynamic imports, I checked TBT (Total Blocking Time) and found that it had increased slightly from its original 0ms.
It wasn’t immediately obvious why reducing the bundle increased blocking, but the cause was again timing.
- Before optimization: the 121KB bundle is parsed all at once on page load. All JavaScript finishes executing before FCP, so there is no main-thread blocking between FCP and TTI, giving TBT = 0.
- After optimization: chunks split out with dynamic imports are lazy-loaded after FCP. Their parsing and execution between FCP and TTI briefly block the main thread, which is reflected in TBT.
TBT adds up the blocking time of long tasks (over 50ms) between FCP and TTI. Previously, that interval had no blocking; the chunk loading timing moved into it.
LCP improved and the TBT increase was small, so I accepted the trade-off. But I saw firsthand that reducing a bundle isn’t automatically better: when it executes matters.
4. heic2any: The Shared Chunk Problem
Where was the size coming from?
Analyzing each page’s bundle with bundle analyzer revealed that heic2any accounted for a large portion.

ƒ /popup/[id] 121 kB 372 kB
It turned out plenty of other people had the same concern.
Next.js separates modules shared across multiple pages into a shared chunk. Importing one in the root layout puts it into that shared chunk, adding it to every page’s first load. HEIC conversion was needed only on the image upload page, but it had been following the entire app around.
- Size decreased, but first load actually increased. So I switched from importing the script in the root layout to loading it dynamically on the page that uses it.
// Before: import in the global layout
import { heic2any } from 'heic2any';
// After: load dynamically only on the page that uses it
<Script
src="heic2any.js"
loading="lazy"
fetchPriority="low"
/>
Alongside this, I switched the related popup and map components on the popup detail page to dynamic imports and removed review-related prefetching.
Before: ƒ /popup/[id] 121 kB 372 kB
After: ƒ /popup/[id] 38.5 kB 359 kB
Popup detail page: 121KB → 38.5KB (68% reduction). This isn’t the result of removing heic2any alone; it’s the combined effect of dynamic imports, removing prefetching, and replacing the script loading approach.

5. Reducing Fetch Calls
Why is minimizing fetches important?
Improving perceived loading speed matters on slow networks (3G/LTE, overseas connections, WebViews). Reducing the RSC payload and hydration payload also improves initial paint stability.
- Immediately render only what’s needed for the first screen.
- Load the rest lazily.
Before

After

- Voting API: call only when
inView. - Latest information API: group with
useQueriesfor parallel processing. - Authentication state: add an
isAuthenticatedoption.
On the popup list and detail pages, I removed unnecessary prefetching and changed recommendation APIs near the bottom to run only on scroll.
The number of JavaScript chunks also fell to 56.
6. Runtime Performance
Analysis with 4× CPU throttling
After reducing the build bundles, I analyzed runtime performance in the Performance tab with 4× CPU throttling.

Loading: 16ms
Scripting: 3,927ms
Rendering: 1,222ms
Painting: 535ms
The network wasn’t the problem (Loading: 16ms). Scripting was the bottleneck. Frame times repeatedly exceeded 2,000ms.
At 60fps, a frame needs to finish within 16ms. If the main thread stays occupied for thousands of milliseconds, scrolling feels like “it moves, but doesn’t follow my finger.”
Why it feels bad despite decent LCP/CLS/INP
LCP measures the initial render only once, and INP is also based on a representative interaction. A structure where infinite scrolling, list image loading, analytics events, and IntersectionObserver callbacks continuously occupy the main thread isn’t captured by Core Web Vitals.
Warnings from Insights in the Performance tab:
- Optimize DOM size
- Improve image delivery (26MB)
- Use efficient cache lifetimes (21MB)
This remains an area for further improvement.
Results at a Glance
| Metric | Before | After |
|---|---|---|
| Home page size | 20.9 kB | 17.9 kB |
| Popup detail page | 121 kB | 38.5 kB (68% ↓) |
| Home first load | 338 kB | 340 kB (+2kB) |
| JavaScript chunks | — | 56 fewer |
| TBT | 0ms | Slight increase (dynamic import trade-off) |
The slight increase in home first load came from moving the script when replacing heic2any with a Script tag. I saw firsthand that individual page bundles can shrink while the first-load total increases.