Optimize image loading and enable CDN prerendering - #104
Open
injoon5 wants to merge 2 commits into
Open
Conversation
- 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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Owner
Author
|
@claude what about og image for articles? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
rehypeLazyImages.js): Automatically addsloading="lazy"anddecoding="async"attributes to all<img>elements in markdown, reducing initial page load impactsrc/routes/blog/[slug]/+page.tsandsrc/routes/projects/[slug]/+page.ts): Changedprerender = falsetoprerender = trueso pages are served from CDN edge locations. Language preference is now restored client-side via localStorage/cookie inonMountwith a mounted guard to suppress animations during the initial switchvercel.json): Added Cache-Control header for/images/*with 7-day browser cache and 30-day CDN cache, plus stale-while-revalidate for resiliencesrc/routes/+layout.svelte): Added<link rel="preconnect">to Convex URL to reduce connection latency for real-time featuresImplementation Details
rehypeLazyImagesplugin is integrated into the mdsvex pipeline and only sets lazy/async attributes if not already present, preserving any explicit configurationhttps://claude.ai/code/session_01LUqv8ytzvon7XCZLMWyrau