Image Optimization Strategies for Pixelfed Photo Viewer

πŸ” Part 1: Inspecting Undocumented APIs

How to Discover API Structure Without Documentation

When working with APIs (especially undocumented ones), you can learn everything you need directly from the response:

  1. Console Logging (What we just added)

  2. Browser DevTools Network Tab

  3. Browser DevTools Console

  4. TypeScript/Type Definitions (if available)

  5. API Response Headers

What We’re Looking For in Pixelfed API

Based on Mastodon API (which Pixelfed is based on), media attachments typically have:

Next Steps: After you load the page, check the browser console to see what fields are actually available!


πŸš€ Part 2: Netlify Optimization Strategies

Since you control your Netlify hosting, here are optimization ideas that work with Astro (and will carry forward):

1. Netlify Image CDN (Netlify Image Optimization)

Netlify has built-in image optimization that works as a proxy/CDN:

<!-- Instead of direct Pixelfed URL -->
<img src="https://pixelfed.social/storage/media/abc123.jpg">

<!-- Use Netlify's image CDN -->
<img src="/.netlify/images?url=https://pixelfed.social/storage/media/abc123.jpg&w=400&q=80">

Benefits:

Implementation:

Note: Requires Netlify Image Optimization addon (may have usage limits on free tier)

2. Netlify Edge Functions (Image Proxy)

Create a Netlify Edge Function that:

Benefits:

Implementation:

3. Netlify Redirects for Image Caching

Use Netlify’s redirect rules to:

# netlify.toml
[[redirects]]
  from = "/pixelfed-images/*"
  to = "https://pixelfed.social/storage/:splat"
  status = 200
  force = true
  headers = { Cache-Control = "public, max-age=31536000, immutable" }

4. Netlify Build Plugins

Create a build-time plugin that:

Benefits:

5. Service Worker for Image Caching

Use a service worker to:

Benefits:


☁️ Part 3: AWS S3 Optimization Strategies

Since you have AWS S3, here are strategies that leverage your existing infrastructure:

1. S3 as Image Cache/Proxy

Architecture:

Pixelfed β†’ Netlify Function β†’ S3 β†’ CloudFront β†’ Browser

Flow:

  1. Netlify Function receives request for image
  2. Checks S3 cache first
  3. If not cached, fetches from Pixelfed
  4. Resizes/optimizes image
  5. Uploads to S3
  6. Serves from S3 (or CloudFront)

Benefits:

2. S3 + Lambda@Edge for Dynamic Resizing

Use Lambda@Edge with CloudFront to:

URL Pattern:

https://cdn.yoursite.com/images/abc123.jpg?w=400&h=300&q=80

Benefits:

3. S3 + Sharp for Batch Processing

Create a Netlify Function that:

S3 Structure:

s3://your-bucket/pixelfed/
  β”œβ”€β”€ thumb/
  β”‚   └── photo-123.jpg
  β”œβ”€β”€ medium/
  β”‚   └── photo-123.jpg
  └── large/
      └── photo-123.jpg

Benefits:

4. S3 Lifecycle Policies for Cost Optimization

Set up S3 lifecycle rules:

5. CloudFront Signed URLs (If Needed)

If you want to control access:


Phase 1: Quick Wins (No Infrastructure Changes)

  1. βœ… Add API inspection logging (done)
  2. Use preview_url if available for gallery thumbnails
  3. Add loading="lazy" to gallery images
  4. Implement connection-aware loading

Phase 2: Netlify Optimization (Medium Effort)

  1. Use Netlify Image CDN (if available on your plan)
  2. Or create Netlify Edge Function for image proxy
  3. Cache images with appropriate headers

Phase 3: AWS Integration (More Effort, More Control)

  1. Set up S3 bucket for image cache
  2. Create Netlify Function to fetch/optimize/store
  3. Serve from S3 via CloudFront
  4. Implement batch processing for new images

πŸ“Š Performance Comparison

Current Setup

After Quick Wins

After Netlify Optimization

After AWS Integration


πŸ”§ Next Steps

  1. Check the console after loading the page to see what the API returns
  2. Choose optimization level based on your needs
  3. Start with Phase 1 (quick wins) - I can implement these now
  4. Evaluate results before moving to Phase 2/3

Would you like me to implement Phase 1 optimizations once we see what the API returns?