Skip to content

Optimize image loading and enable CDN prerendering - #104

Open
injoon5 wants to merge 2 commits into
mainfrom
claude/pensive-shannon-befQW
Open

Optimize image loading and enable CDN prerendering#104
injoon5 wants to merge 2 commits into
mainfrom
claude/pensive-shannon-befQW

Conversation

@injoon5

@injoon5 injoon5 commented May 28, 2026

Copy link
Copy Markdown
Owner

Summary

This PR improves performance by enabling CDN edge prerendering for blog and project pages, adding lazy loading to all markdown images, and configuring aggressive caching for image assets.

Key Changes

  • New rehype plugin (rehypeLazyImages.js): Automatically adds loading="lazy" and decoding="async" attributes to all <img> elements in markdown, reducing initial page load impact
  • Enable prerendering for blog and project detail pages (src/routes/blog/[slug]/+page.ts and src/routes/projects/[slug]/+page.ts): Changed prerender = false to prerender = true so pages are served from CDN edge locations. Language preference is now restored client-side via localStorage/cookie in onMount with a mounted guard to suppress animations during the initial switch
  • Image caching headers (vercel.json): Added Cache-Control header for /images/* with 7-day browser cache and 30-day CDN cache, plus stale-while-revalidate for resilience
  • Convex preconnect (src/routes/+layout.svelte): Added <link rel="preconnect"> to Convex URL to reduce connection latency for real-time features

Implementation Details

  • The rehypeLazyImages plugin is integrated into the mdsvex pipeline and only sets lazy/async attributes if not already present, preserving any explicit configuration
  • Prerendering now relies on client-side language restoration instead of server-side cookie handling, enabling full static generation while maintaining language preference UX

https://claude.ai/code/session_01LUqv8ytzvon7XCZLMWyrau

claude added 2 commits May 28, 2026 17:00
- Enable prerender=true on blog/[slug] so posts are served from CDN
  edge instead of a cold-start serverless function on every hit.
  Language preference is restored client-side via the existing onMount
  localStorage/cookie path; the mounted guard suppresses animations
  during that switch so there is no visible flash.
- Add rehypeLazyImages plugin: injects loading="lazy" decoding="async"
  on all markdown <img> elements, preventing off-screen images from
  blocking page load.

https://claude.ai/code/session_01LUqv8ytzvon7XCZLMWyrau
- Enable prerender=true on projects/[slug] (same pattern as blog/[slug]).
- Add <link rel="preconnect"> for PUBLIC_CONVEX_URL in root layout so the
  browser starts the DNS/TCP/TLS handshake to Convex before JS executes,
  reducing WebSocket cold-start latency for real-time data.
- Add Cache-Control headers for /images/* in vercel.json:
  7-day browser TTL, 30-day CDN TTL, 1-day stale-while-revalidate.
  Images are not URL-fingerprinted so immutable is avoided.

https://claude.ai/code/session_01LUqv8ytzvon7XCZLMWyrau
@vercel

vercel Bot commented May 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
web Error Error May 28, 2026 5:03pm

@injoon5

injoon5 commented May 29, 2026

Copy link
Copy Markdown
Owner Author

@claude what about og image for articles?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants