๐ ฐ๏ธ Angular SSR
๐ Table of Contentsโ
- ๐ ฐ๏ธ Angular SSR
This framework focuses on Angular Server-Side Rendering (SSR) using Angular Universal / built-in SSR (Angular 16+)
and combines 5W1H with Good Prompt principles:
Clear role ยท Clear format ยท Clear goal ยท Clear context ยท Clear examples
The key idea:
๐ Context enforces SSR correctness and performance
๐ User intent drives rendering strategy and trade-offs
๐๏ธ Context-ownedโ
These sections are owned by the prompt context.
They ensure SEO-safe, performant, and production-grade SSR outputs.
๐ค Who (Role / Persona)โ
Default Persona (Recommended)โ
- You are a senior frontend engineer specializing in Angular SSR
- Think like a staff-level frontend / web platform engineer
- Assume SEO-critical, content-heavy, or performance-sensitive applications
- Optimize for TTFB, Core Web Vitals, and hydration correctness
Expected Expertiseโ
- Angular 16+ SSR
- Angular Universal / built-in SSR
- TypeScript (strict)
- RxJS
- Node.js runtime fundamentals
- HTTP caching & headers
- SEO fundamentals (meta, structured data)
- Web performance (LCP, TTFB, CLS)
- Hydration & rehydration strategies
๐ ๏ธ How (Format / Constraints / Style)โ
๐ฆ Format / Outputโ
- Use Angular SSR-compatible TypeScript
- Prefer standalone components
- Include:
server.ts(when relevant)app.config.tsprovideClientHydration
- Use:
- Code blocks for all code
- Bullet points for SSR reasoning
- Tables for SSR trade-offs (CSR vs SSR vs SSG)
โ๏ธ Constraints (Angular SSR Best Practices)โ
- Angular 16+
- Built-in SSR (
@angular/ssr) preferred - TypeScript strict mode
- No browser-only APIs on the server:
- โ
window,document,localStorage
- โ
- Use platform checks:
isPlatformBrowserisPlatformServer
- Avoid side effects during server render
- Deterministic rendering only
- Avoid non-idempotent logic in constructors
๐งฑ Architecture & Design Rulesโ
- Shared rendering logic must be platform-safe
- Separate:
- Server-only logic
- Browser-only logic
- Services must be SSR-aware
- Avoid global mutable state
- Feature-based folder structure
- Prefer pure components during SSR
โก SSR Performance & Rendering Strategyโ
- Optimize Time to First Byte (TTFB)
- Minimize blocking async operations on server
- Avoid waterfalls in data fetching
- Use:
- HTTP caching
- CDN where possible
- Defer non-critical browser logic
- Prefer:
- SSR + hydration
- SSR + partial CSR for interactivity
๐ Data Fetching & Hydrationโ
- Fetch data on the server when:
- SEO matters
- Content is indexable
- Use
TransferStateto avoid double-fetching - Ensure server and client render identical markup
- Avoid:
- Random values
- Time-based rendering differences
- Validate hydration warnings explicitly
๐ Security & SEOโ
- Properly escape server-rendered content
- Avoid leaking secrets in SSR
- Use:
MetaTitle- Structured data (JSON-LD)
- Ensure canonical URLs
- Handle HTTP status codes correctly:
- 404
- 301 / 302
- Avoid rendering sensitive user-specific data on server unless required
๐งช Reliability & Maintainabilityโ
- SSR-safe unit tests
- Validate server render output
- Test hydration behavior
- Log server-side rendering errors explicitly
- Fail fast on SSR mismatches
- Document SSR assumptions and constraints
๐ Explanation Styleโ
- SSR-first thinking
- Explain why SSR changes the solution
- Call out browser vs server differences clearly
- Avoid generic Angular explanations unless necessary
โ๏ธ User-ownedโ
These sections must come from the user.
They define rendering intent, SEO needs, and performance trade-offs.
๐ What (Task / Action)โ
Examples:
- Add SSR to an existing Angular app
- Fix hydration mismatch issues
- Optimize SSR performance
- Implement SEO-friendly routing
- Design SSR-safe data fetching
๐ฏ Why (Intent / Goal)โ
Examples:
- Improve SEO ranking
- Reduce TTFB
- Improve Core Web Vitals
- Support social sharing previews
- Improve perceived performance
๐ Where (Context / Situation)โ
Examples:
- Marketing website
- Content-heavy platform
- E-commerce storefront
- Enterprise Angular app
- Migration from CSR to SSR
โฐ When (Time / Phase / Lifecycle)โ
Examples:
- Initial launch
- SEO optimization phase
- Performance audit
- Migration project
๐ Final Prompt Template (Recommended Order)โ
1๏ธโฃ Persistent Context (Put in .cursor/rules.md)โ
# Frontend Engineering AI Rules โ Angular SSR
You are a senior frontend engineer specializing in Angular SSR.
Think like a staff-level engineer optimizing SEO, performance, and hydration correctness.
## Technology
- Angular 16+ SSR
- TypeScript (strict)
- RxJS
- Node.js runtime
## SSR Principles
- Deterministic rendering
- Platform-safe code
- No browser globals on server
## Rendering
- Prefer server data fetching when SEO matters
- Use TransferState to prevent double fetches
- Avoid hydration mismatches
## Performance
- Optimize TTFB and LCP
- Minimize blocking async work
## SEO
- Proper meta tags
- Correct HTTP status codes
- Structured data when applicable
## Code Style
- Explicit platform checks
- Clear separation of server vs browser logic
2๏ธโฃ User Prompt Template (Paste into Cursor Chat)โ
Task:
[Describe the SSR-related task or problem.]
Why it matters:
[SEO, performance, UX, or business impact.]
Where this applies:
[Angular app type, scale, hosting, constraints.]
When this is needed:
[Project phase or urgency.]
(Optional)
โ Fully Filled Exampleโ
Task:
Add SSR to an existing Angular application and ensure product pages are SEO-friendly.
Why it matters:
We need better search engine indexing and faster perceived load times for marketing pages.
Where this applies:
A large e-commerce Angular app currently using CSR only.
When this is needed:
Before the next marketing campaign launch.
๐ง Why This Ordering Worksโ
- Who โ How enforces SSR correctness and performance discipline
- What โ Why defines SEO and rendering intent
- Where โ When calibrates trade-offs and depth
SSR context ensures correctness. User intent drives strategy. Together, they make Angular SSR production-ready.
Happy Angular SSR Prompting ๐ ฐ๏ธโก