web-development7 min
Next.js Image Storage on R2/Arvan: Custom Loader and Edge Cache
By Arash Latifi
Move shop images to R2/Arvan and serve via custom Next.js loader — 70% less VPS traffic and half LCP.
TL;DR: Don't keep images local — put them on R2/Arvan and use a custom
loaderso/_next/imagecomes from edge.
Why R2?
Iran VPS burns CPU for every /_next/image. R2 serves from edge.
Implementation
Checklist
- [ ] R2/Arvan bucket + CDN domain
- [ ]
loaderFile+remotePatternsfor CDN - [ ] Verify
avifin Network
FAQ
Cost? R2: 10GB free, then $0.015/GB. Arvan similar.
SEO?
Canonical URL stays /products/p1.jpg — only loader changes.
Diff from image optimization? This is the next step — storage + edge.