Video Production Plan : Video 7 — Performance, Images, Environments, and CLI Migrations
Video 7 — Performance, Images, Environments, and CLI Migrations
| Attribute | Details |
|---|---|
| Course | 3 (APIs and Developer Tooling), Module 3.2 (lessons 3-4) + Module 3.3 |
| Covers | Lessons 3.2.3, 3.2.4, 3.3.1, 3.3.2, 3.3.3 |
| Priority | Core |
| Length | 20-28 min |
| Format | Screencast (terminal + Contentstack UI + code editor) |
| Status | Not started |
Why This Video Matters
This turns Contentstack from a simple content source into an operationally mature implementation. A working integration is not the same thing as a production-ready integration.
Outline
- Image Delivery API: URL-based transformations (resize, crop, format conversion, quality)
- Show image transformation parameters and their impact on page performance
- Responsive image strategies
- Caching strategies: CDN behavior, cache invalidation on publish, stale-while-revalidate patterns
- Frontend rendering strategies: SSG (build-time), SSR (request-time), ISR (incremental), CSR (client-side) — when each makes sense
- Environments explained: development, staging, production — each with its own publish queue and delivery token
- Content promotion: publishing to dev first, then staging, then production
- Aligning CMS environments with CI/CD pipelines
- Contentstack CLI (csdx): installation, authentication, key commands
- Live demo: export a stack, import into another, run a content type migration
- Migration scripts: programmatically creating and modifying content types
- When to use CLI vs UI vs Management API
Key Lines
"A working integration is not the same thing as a production-ready integration."
"Environment strategy is where content delivery and deployment reality meet."
"The CLI is where repeatability starts to replace manual effort."
Detailed Talking Points
1. Image Delivery API: URL-based transformations
- Contentstack serves every uploaded asset through its Image Delivery CDN — the URL you get back from the Delivery API is already on the CDN.
- Transformations are query parameters appended to the URL: ?width=400, ?height=300, ?format=webp, ?quality=80, ?crop=400,400,x100,y50, ?fit=crop.
- No build step, no image processing pipeline, no Lambda function — the CDN handles transformation and caching at the edge.
- The ?auto=webp parameter is the easiest win: it inspects the browser's Accept header and serves WebP when supported, falling back automatically. Typical savings: 25-35% payload reduction.
- Region matters for the host: NA uses images.contentstack.io, EU uses eu-images.contentstack.com, Azure variants exist too.
- Combined parameters in one URL: ?width=800&height=600&fit=crop&format=webp&quality=80 — one request, one cached result.
2. Image transformation parameters and performance impact
- Show a before/after: original 4000px product image vs. ?width=800&auto=webp&quality=80. Compare file sizes in the Network tab.
- Quality between 70-85 is the sweet spot for product photography. Below 60, compression artifacts become visible.
- The fit parameter controls behavior when both width and height are set: bounds scales to fit within dimensions, crop fills exact dimensions and trims overflow.
- trim=20,20,20,20 removes uniform whitespace — useful for product catalog images with inconsistent borders.
- The key principle: always match ?width= to the rendered size. A 4000px image displayed at 800px wastes bandwidth and tanks your LCP score.
3. Responsive image strategies
- Use srcset to give the browser multiple width options: 400w, 800w, 1200w, 1600w — all generated by varying the ?width= parameter on the same base URL.
- Pair srcset with sizes to tell the browser how wide the image renders at each breakpoint: (max-width: 640px) 100vw, (max-width: 1024px) 50vw, 33vw.
- Build a buildImageUrl() and buildSrcSet() utility function rather than constructing URLs manually — avoids string concatenation bugs and enforces consistent quality/format settings.
- Art direction with different crops: use ?crop= or ?fit=crop with different aspect ratios for mobile vs. desktop hero images.
- Always set explicit width and height attributes on <img> elements to prevent CLS (Cumulative Layout Shift).
- Use loading="lazy" for below-fold images, omit it (or use loading="eager") for above-fold hero images.
- Preload the LCP image with <link rel="preload" as="image" fetchpriority="high">.
4. Caching strategies
- Contentstack's CDN invalidates on publish — when an editor publishes or unpublishes, stale cache entries are evicted globally within seconds.
- Between publishes, identical API calls resolve at the CDN edge without hitting origin servers.
- Draft saves do not affect the delivery cache. Only the publish action triggers invalidation.
- Contentstack sends Cache-Control: public, max-age=0, must-revalidate — the CDN is the source of truth, not the browser cache.
- If you add your own caching layer (Redis, edge cache, in-memory), you must add webhook-driven invalidation. Contentstack only purges its own CDN, not yours.
- The stale-while-revalidate pattern: serve cached content immediately, fetch fresh content in the background. Ideal for content that updates periodically but where a few seconds of staleness is acceptable.
5. Frontend rendering strategies
- SSG (Static Site Generation): pages built at build time, served from static CDN. Fastest possible load. Content only updates on rebuild. Best for: stable pages, reference content, documentation.
- SSR (Server-Side Rendering): page generated on every request. Always fresh. Adds latency (API call + render). Best for: personalized content, search results, breaking news.
- ISR (Incremental Static Regeneration): hybrid — static pages that regenerate after a time interval or on-demand. Combine revalidate = 60 with webhook-triggered revalidation for best of both worlds.
- CSR (Client-Side Rendering): SPA pattern, content fetched in the browser after initial load. No SEO benefit from CMS content. Best for: authenticated dashboards, interactive tools.
- For Veda: homepage gets ISR with 30s revalidation, product pages get ISR with 60s, category pages get SSG with webhook-triggered rebuilds, search results get SSR.
- Webhook-triggered rebuilds close the loop: editor publishes → Contentstack fires webhook → hosting platform triggers rebuild → new static site deploys in 30-120 seconds.
6. Environments explained
- An environment in Contentstack is a deployment target, not a code branch. This trips up developers from git-centric workflows.
- Typical setup: development (dev integration testing), staging (QA and stakeholder review), production (live customer-facing).
- Each environment gets its own delivery token. Your production frontend uses a production-scoped token. Staging uses a different token.
- Token isolation limits blast radius — if a staging token leaks, production content is unaffected.
- Each environment has independent published content state. Publishing to staging does not make content available in production.
- Environments have a Base URL (the frontend that consumes content) and an optional Preview URL for Live Preview.
7. Content promotion flow
- Promotion strategy mirrors application deployment: dev → staging → production.
- Editor creates entry, publishes to development. Developer verifies rendering. Editor promotes to staging for QA review. Senior editor publishes to production.
- Each publish action is explicit and auditable. Content does not drift between environments without intentional action.
- Publish rules restrict which roles can publish where: Content Authors to dev only, Content Managers to dev and staging, Senior Editors to production.
- Publish assets before the entries that reference them to avoid broken references on the target environment.
- The publish queue processes requests asynchronously — clicking Publish does not guarantee instant CDN availability. Monitor the queue for large bulk operations.
8. Aligning CMS environments with CI/CD pipelines
- Content publishes and code deploys operate on independent timelines — this independence is a feature, not a flaw, but it creates a coordination problem.
- The primary integration point: webhooks. Contentstack fires HTTP webhooks on publish events. Point them at your build hook (Vercel deploy hook, Netlify build hook, GitHub Actions dispatch).
- Filter webhooks by environment and content type. Development publishes should not trigger production builds. Metadata-only content types should not trigger rebuilds.
- Content-as-code: export content type schemas with the CLI, commit them to version control. Add a CI step that detects schema drift between Contentstack and your committed definitions.
- Manage delivery tokens as CI/CD secrets. Each CI/CD context (preview, staging, production) injects the correct token via environment variables.
- Rollback order matters: revert code first (restore the frontend that expects the old schema), then republish previous content versions.
9. Contentstack CLI: installation, authentication, key commands
- Install globally: npm install -g @contentstack/cli. Verify with csdx --version.
- Interactive login: csdx auth:login opens browser-based OAuth. Good for local dev, not for CI/CD.
- Token-based auth for automation: csdx auth:tokens:add --alias "my-stack" --stack-api-key "..." --management --token "..." --yes.
- Token aliases simplify repeated operations — reference --alias my-stack instead of passing raw keys every time.
- List stored tokens: csdx auth:tokens. Remove a token: csdx auth:tokens:remove --alias "my-stack".
- The CLI uses a plugin architecture. Core commands cover stack management, content export/import, and authentication.
10. Live demo: export, import, and migration
- Export a full stack: csdx cm:stacks:export --alias "source" --data-dir ./export-data.
- Export specific modules: --module content-types --module global-fields --module assets.
- Show the exported directory structure: JSON files organized by module — content-types/product.json, entries/product/en-us/, assets/.
- Import into target: csdx cm:stacks:import --alias "target" --data-dir ./export-data.
- Use --replace-existing to overwrite existing content types during import.
- Always back up before importing to production: csdx cm:stacks:export --alias "prod" --data-dir ./backup/$(date +%Y%m%d).
- Seed a new stack from a template: csdx cm:stacks:seed --repo "contentstack/stack-starter-app".
11. Migration scripts
- For changes beyond simple export/import — renaming fields, transforming data, backfilling values — use programmatic scripts with the Content Management API.
- Example: backfill a description_word_count field across all Veda product entries. Fetch entries via CMA, calculate the value, update each entry.
- Migration scripts give you full control over transformation logic, error handling, and execution order.
- Wrap CLI export/import in CI/CD pipelines (GitHub Actions workflow) for automated content model sync across multiple stacks.
- Use workflow_dispatch with matrix strategy to fan out imports across brand stacks in parallel.
12. When to use CLI vs UI vs Management API
- UI: one-off content type changes, small-scale content edits, exploratory work. Fast feedback, no scripting needed.
- CLI (csdx): repeatable operations across stacks — export/import, seeding, bulk operations. Scriptable, auditable, belongs in CI/CD.
- Management API (CMA): programmatic migrations, custom tooling, data transformations, backfills. Full control, requires code.
- Rule of thumb: if you are doing it once, use the UI. If you are doing it more than once, use the CLI. If you need transformation logic, use the CMA.
- Treat content migrations like database migrations: plan them, test against non-production, back up before production, log everything.
Screen: What to Show
| Outline Item | What to Show on Screen |
|---|---|
| 1. Image Delivery API | Browser with a Contentstack asset URL. Append ?width=400&format=webp&quality=80 live in the address bar. Show the image changing/resizing in real time. |
| 2. Transformation impact | Chrome DevTools Network tab. Load a product page with original images, then with optimized URLs. Compare file sizes side by side (highlight the KB reduction). |
| 3. Responsive images | Code editor showing a buildImageUrl() and buildSrcSet() utility function. Then the rendered HTML <img> element with srcset in Elements panel. Use Chrome responsive mode to show different image sizes loading at different breakpoints. |
| 4. Caching | Chrome DevTools Network tab — show a Contentstack API response with Cache-Control headers. Then show a publish action in Contentstack UI and the subsequent fresh response. Optionally show a simple stale-while-revalidate code snippet. |
| 5. Rendering strategies | Side-by-side diagram or slide: SSG vs SSR vs ISR vs CSR with arrows showing when the API call happens (build time, request time, background, client). Show Next.js code with revalidate = 60 and a revalidation API route. |
| 6. Environments | Contentstack dashboard: Settings > Environments. Show the three environments (development, staging, production) with their Base URLs. Then Settings > Tokens showing three delivery tokens, one per environment. |
| 7. Content promotion | Contentstack entry editor. Click Publish, show the environment selector. Publish to development first, then show the entry in staging (not yet published), then publish to staging. Show the publish queue (Settings > Publish Queue). |
| 8. CI/CD alignment | Code editor: show a webhook handler that filters by environment and content type. Then Contentstack dashboard: Settings > Webhooks configuration. Optionally show a GitHub Actions schema-drift-check workflow YAML. |
| 9. CLI installation and auth | Terminal: npm install -g @contentstack/cli, csdx --version, csdx auth:tokens:add with alias. Show the token list with csdx auth:tokens. |
| 10. Live demo | Terminal: run csdx cm:stacks:export and show the output directory. Open a JSON file in the editor. Run csdx cm:stacks:import against a target stack. Switch to Contentstack UI to verify the imported content types appear. |
| 11. Migration scripts | Code editor: show a TypeScript migration script that uses @contentstack/management to backfill a field. Run it in the terminal with npx tsx scripts/backfill.ts. Show the updated entries in Contentstack UI. |
| 12. CLI vs UI vs CMA | Simple three-column comparison slide or table on screen. No code needed — just a clear visual summary. |
Veda Scenario Thread
Veda: The Revival Collection (jewelry e-commerce) runs through this entire video as the practical context.
- Images (items 1-3): You are optimizing Veda product images. Start with a Matrix Link Bracelet product photo served at full resolution (4000px). Show how appending ?width=800&auto=webp&quality=80 slashes the file size. Build the buildSrcSet() utility for the product card grid — 300w, 600w, 900w breakpoints for the Pixel Stud Earrings, Circuit Collar Necklace, and Data Drop Earrings product cards. Add <link rel="preload"> for the Digital Dawn hero image on the homepage.
- Caching and rendering (items 4-5): Veda's homepage uses ISR with 30-second revalidation because campaign launches need fast propagation. Product pages use ISR with 60-second revalidation and webhook-triggered on-demand revalidation. Category pages use SSG with webhook-triggered rebuilds. Search results use SSR because query parameters vary per request. Show a webhook handler that triggers a Vercel rebuild only for product, page, and product_line content types on the production environment.
- Environments (items 6-7): Veda has three environments: development at dev.veda.example.com, staging at staging.veda.example.com, production at veda.example.com. Walk through publishing a new seasonal collection entry: publish to dev for developer verification, promote to staging for the merchandising team, then production for the customer-facing storefront. Show how publish rules prevent a junior content author from accidentally pushing an unreviewed product to production.
- CI/CD (item 8): Veda's CI/CD pipeline on Vercel uses environment-specific delivery tokens injected as environment variables. A webhook fires on production publish and triggers a rebuild. The content type schemas are exported and committed to the repo, with a GitHub Actions step that detects schema drift on pull requests.
- CLI and migrations (items 9-12): Veda is expanding from one brand stack to three brand stacks (Alpha, Beta, Gamma). Use the CLI to export the product and category content types from the Alpha stack, import them into Beta and Gamma. Then run a migration script that backfills a description_word_count field across all product entries in all three stacks. Wrap the workflow in a GitHub Actions pipeline with matrix strategy for parallel execution.
Transitions
1 → 2: "Now that you see how the URL parameters work, let us look at the actual performance impact in the browser."
2 → 3: "Optimizing one image is useful — building a system that optimizes every image across your product catalog is what matters."
3 → 4: "Images are cached at the CDN edge, but what about the API responses that tell you which images to show?"
4 → 5: "Caching controls when data refreshes — rendering strategy controls when pages are built from that data."
5 → 6: "Rendering strategies tie to environments, because each environment serves different content to a different audience."
6 → 7: "Having environments is one thing — having a disciplined flow for moving content through them is another."
7 → 8: "Content promotion aligns with code deployment, and that is where CI/CD integration becomes essential."
8 → 9: "The CI/CD pipeline needs tooling to automate content operations, and that tooling is the Contentstack CLI."
9 → 10: "Let us stop talking about the CLI and start using it."
10 → 11: "Export and import handle structural replication — migration scripts handle data transformation."
11 → 12: "With three tools in your belt — CLI, UI, and Management API — you need to know when to reach for each one."
12 → Video 8: "You now have the operational foundation: optimized images, caching strategy, environment discipline, and CLI automation. In the next video, we bring it all together with Contentstack Launch and a full deployment walkthrough."
Common Mistakes to Call Out
- Serving full-resolution images at display size. A 4000px image displayed at 800px wastes bandwidth and destroys your LCP score. Always match ?width= to the rendered size.
- Skipping auto=webp. A single query parameter reduces payload by 25-35% with zero effort. There is no reason not to use it.
- Missing width and height attributes on <img> elements. Without them, the browser cannot reserve space before the image loads, causing layout shifts that tank your CLS score.
- Adding a caching layer without webhook-driven invalidation. Contentstack only invalidates its own CDN. If you add Redis, edge cache, or in-memory cache without a purge mechanism, editors publish content that never appears on the site.
- Using SSR for everything. SSR guarantees freshness but wastes resources on pages that rarely change. Product pages, category pages, and documentation should use SSG or ISR.
- Confusing environments with branches. Environments are deployment targets (dev, staging, production). Branches are for parallel content development. Creating an environment called feature-new-checkout is misusing the system.
- Publishing directly to production without staging verification. Skipping staging saves a few minutes and costs hours when broken content, missing references, or layout issues reach customers.
- Sharing delivery tokens across environments. Using the production token in your staging frontend defeats environment isolation. Each frontend deployment must use the token scoped to its corresponding environment.
- Publishing entries before their referenced assets. A product entry referencing an unpublished hero image produces a broken storefront page. Publish assets first.
- Running --replace-existing imports on production without a backup. Always export the current state before migrating production: csdx cm:stacks:export --alias "prod" --data-dir ./backup/$(date +%Y%m%d).
- N+1 query patterns in template loops. A loop over 20 products that fetches product line data per iteration makes 21 API calls instead of 1. Use includeReference() to resolve references in the original query.
- Hardcoding stack credentials in migration scripts. Use environment variables or the CLI's token alias system. Never commit API keys or management tokens to version control.
Notes
Use this space for recording notes, script drafts, or post-production feedback.