Cursor rule
.cursor/rules/astro-performance-patterns.mdcPerformance optimization patterns for Astro applications
Cursor rules
Quality
62/100
Scores the file, not the repository.Length
626 words
13 headings · 6 code blocksRepository
0
— · pushed 262 days agoLast changed
3 days ago
First indexed 3 days ago.123456# Astro Performance Patterns78## Server-Side vs Client-Side Decision Matrix910### ✅ Use Server-Side Rendering (SSR) For:11- **Initial page data**: Historical data, user profiles, product listings12- **SEO-critical content**: Meta information, structured data, primary content13- **Static or slow-changing data**: Configuration, settings, reference data14- **Database queries**: Direct database access for initial data load15- **API aggregation**: Combining multiple API calls into single server request1617### ✅ Use Client-Side Rendering (CSR) For:18- **Real-time updates**: Live chat, stock prices, notification feeds19- **User interactions**: Form validation, interactive filters, dynamic searches20- **Progressive enhancement**: Adding interactivity to server-rendered content21- **Client-only APIs**: Geolocation, camera, local storage, WebRTC22- **Infinite scroll/pagination**: Loading additional content on demand2324## Performance Optimization Patterns2526### Data Prefetching in Frontmatter27```astro28---29// ✅ GOOD: Aggregate multiple API calls server-side30const [userData, postsData, commentsData] = await Promise.allSettled([31 userService.getUser(userId),32 postService.getPosts(userId),33 commentService.getComments(userId)34]);3536// Transform results with error handling37const user = userData.status === 'fulfilled' ? userData.value : null;38const posts = postsData.status === 'fulfilled' ? postsData.value : [];39const comments = commentsData.status === 'fulfilled' ? commentsData.value : [];40---4142<!-- ❌ AVOID: Multiple client-side API calls -->43<!-- <script>44 Promise.all([45 fetch('/api/user'),46 fetch('/api/posts'),47 fetch('/api/comments')48 ]).then(...)49</script> -->50```5152### Conditional Loading Strategies53```astro54---55interface Props {56 priority: 'high' | 'low';57 symbol: string;58}5960const { priority, symbol } = Astro.props;6162// Load expensive data only for high-priority requests63let expensiveData: any = null;64if (priority === 'high') {65 try {66 expensiveData = await expensiveService.getDetailedAnalysis(symbol);67 } catch (err) {68 console.error('Failed to load detailed analysis:', err);69 }70}7172// Always load basic data73const basicData = await basicService.getQuickData(symbol);74---7576<div>77 <!-- Always show basic data -->78 <BasicDataDisplay data={basicData} />7980 <!-- Conditionally show expensive data -->81 {expensiveData && (82 <DetailedAnalysis data={expensiveData} />83 )}8485 <!-- Client-side enhancement for low priority -->86 {priority === 'low' && (87 <button id="load-details" data-symbol={symbol}>88 Load Detailed Analysis89 </button>90 )}91</div>9293{priority === 'low' && (94 <script>95 document.getElementById('load-details')?.addEventListener('click', async (e) => {96 const symbol = e.target.dataset.symbol;97 const response = await fetch(`/api/detailed-analysis?symbol=${symbol}`);98 // Handle client-side loading for low priority99 });100 </script>101)}102```103104### Caching Strategies105```astro106---107// Use service-level caching for expensive operations108const cacheKey = `analysis_${symbol}_${new Date().toDateString()}`;109110let analysisData: any;111try {112 // Check cache first113 analysisData = await cacheService.get(cacheKey);114115 if (!analysisData) {116 // Compute and cache117 analysisData = await expensiveAnalysisService.analyze(symbol);118 await cacheService.set(cacheKey, analysisData, 3600); // 1 hour cache119 }120} catch (err) {121 console.error('Analysis cache error:', err);122 analysisData = null;123}124---125```126127## Bundle Size Optimization128129### Minimal Client-Side JavaScript130```astro131<!-- ✅ GOOD: Minimal client enhancement -->132<button id="toggle-details" data-expanded="false">133 Show Details134</button>135136<div id="details" class="hidden">137 <!-- Server-rendered content -->138</div>139140<script>141 // Simple DOM manipulation only142 document.getElementById('toggle-details')?.addEventListener('click', (e) => {143 const details = document.getElementById('details');144 const expanded = e.target.dataset.expanded === 'true';145146 details?.classList.toggle('hidden', expanded);147 e.target.dataset.expanded = (!expanded).toString();148 e.target.textContent = expanded ? 'Show Details' : 'Hide Details';149 });150</script>151152<!-- ❌ AVOID: Heavy client-side frameworks for simple interactions -->153```154155### Lazy Loading with client:visible156```astro157---158// Heavy component that should load only when visible159import HeavyChart from './heavy_chart.astro';160---161162<div>163 <!-- Critical above-the-fold content renders immediately -->164 <CriticalContent />165166 <!-- Heavy component loads only when scrolled into view -->167 <HeavyChart client:visible />168</div>169```170171## Database Query Optimization172173### Efficient Data Loading174```astro175---176// ✅ GOOD: Single optimized query177const combinedData = await db.prepare(`178 SELECT179 s.symbol, s.current_price,180 COUNT(o.id) as option_count,181 MAX(score.total_score) as max_score182 FROM stock_snapshots s183 LEFT JOIN option_snapshots o ON s.id = o.snapshot_id184 LEFT JOIN option_score_snapshots score ON o.id = score.option_snapshot_id185 WHERE s.symbol = ? AND s.created_at >= ?186 GROUP BY s.id187 ORDER BY s.created_at DESC188 LIMIT 10189`).bind(symbol, cutoffDate).all();190191// ❌ AVOID: Multiple separate queries192// const stocks = await getStocks(symbol);193// const options = await getOptions(stockId);194// const scores = await getScores(optionId);195---196```
Also in sferg989/fergfo.om
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| sferg989/fergfo.om.cursor/rules/astro-component-structure.mdc · 0 | Cursor rules | stylearchui | 58/100 | 3 days ago | |
| sferg989/fergfo.om.cursor/rules/astro-database-integration.mdc · 0 | Cursor rules | database | 50/100 | 3 days ago | |
| sferg989/fergfo.om.cursor/rules/astro-error-handling.mdc · 0 | Cursor rules | styledatabaseui | 58/100 | 3 days ago | |
| sferg989/fergfo.om.cursor/rules/astro-ssr-patterns.mdc · 0 | Cursor rules | style | 49/100 | 3 days ago | |
| sferg989/fergfo.om.cursor/rules/ts-typecheck.mdc · 0 | Cursor rules | do-not | 23/100 | 3 days ago | |
| sferg989/fergfo.om.cursor/rules/ts.mdc · 0 | Cursor rules | styletypesdo-notdocs | 55/100 | 3 days ago | |
| sferg989/fergfo.om.cursorrules · 0 | .cursorrules | do-not | 49/100 | 3 days ago | |
| sferg989/fergfo.omCLAUDE.md · 0 | CLAUDE.md | setupbuildteststyle+7 | 89/100 | 3 days ago |
Diff against .cursor/rules/astro-component-structure.mdc Diff against .cursor/rules/astro-database-integration.mdc Diff against .cursor/rules/astro-error-handling.mdc Diff against .cursor/rules/astro-ssr-patterns.mdc Diff against .cursor/rules/ts-typecheck.mdc Diff against .cursor/rules/ts.mdc Diff against .cursorrules Diff against CLAUDE.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 3 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago |
