@ssheleg/sheleg-dev 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +172 -0
- package/LICENSE +21 -0
- package/README.md +132 -0
- package/SECURITY.md +63 -0
- package/bin/sheleg-dev.js +99 -0
- package/package.json +45 -0
- package/plugins/sheleg-dev/.claude-plugin/plugin.json +28 -0
- package/plugins/sheleg-dev/skills/ad-tracking/SKILL.md +442 -0
- package/plugins/sheleg-dev/skills/ad-tracking/references/consent-mode.md +257 -0
- package/plugins/sheleg-dev/skills/ad-tracking/references/event-tracking.md +201 -0
- package/plugins/sheleg-dev/skills/ad-tracking/references/gtag-api.md +389 -0
- package/plugins/sheleg-dev/skills/ad-tracking/references/meta-linkedin.md +103 -0
- package/plugins/sheleg-dev/skills/ad-tracking/references/performance-security.md +288 -0
- package/plugins/sheleg-dev/skills/crypto-payments/SKILL.md +384 -0
- package/plugins/sheleg-dev/skills/crypto-payments/references/heleket-provider.md +1357 -0
- package/plugins/sheleg-dev/skills/frontend-performance/SKILL.md +147 -0
- package/plugins/sheleg-dev/skills/frontend-performance/references/accessibility-perf.md +172 -0
- package/plugins/sheleg-dev/skills/frontend-performance/references/css-performance.md +180 -0
- package/plugins/sheleg-dev/skills/frontend-performance/references/nextjs.md +271 -0
- package/plugins/sheleg-dev/skills/google-auth/SKILL.md +275 -0
- package/plugins/sheleg-dev/skills/google-auth/references/adc-and-service-accounts.md +464 -0
- package/plugins/sheleg-dev/skills/google-auth/references/oauth2-web-server.md +615 -0
- package/plugins/sheleg-dev/skills/google-auth/references/sign-in-with-google.md +593 -0
- package/plugins/sheleg-dev/skills/google-auth/references/workload-identity.md +376 -0
- package/plugins/sheleg-dev/skills/google-signin/SKILL.md +121 -0
- package/plugins/sheleg-dev/skills/google-signin/references/full-guide.md +421 -0
- package/plugins/sheleg-dev/skills/stripe-billing/SKILL.md +458 -0
- package/plugins/sheleg-dev/skills/stripe-billing/references/price-integrity.md +201 -0
- package/plugins/sheleg-dev/skills/stripe-billing/references/stripe-agent-toolchain.md +173 -0
- package/plugins/sheleg-dev/skills/stripe-billing/references/subscription-lifecycle.md +294 -0
- package/plugins/sheleg-dev/skills/stripe-billing/references/testing-and-local-dev.md +214 -0
- package/plugins/sheleg-dev/skills/stripe-billing/references/webhook-events.md +211 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: frontend-performance
|
|
3
|
+
description: >-
|
|
4
|
+
Use when building or auditing web pages for performance — running PageSpeed Insights,
|
|
5
|
+
optimizing Lighthouse scores, fixing render-blocking resources, reducing bundle size,
|
|
6
|
+
improving load times, or diagnosing slow page rendering. Covers Core Web Vitals (LCP, FCP,
|
|
7
|
+
CLS, INP, TBT, Speed Index), font loading strategies, CSS animation compositing, JavaScript
|
|
8
|
+
bundle optimization, cache headers, code splitting, Content Security Policy, image
|
|
9
|
+
optimization, and the contrast and heading issues that move a Lighthouse score. Triggers -
|
|
10
|
+
"performance audit", "PageSpeed", "Lighthouse", "Core Web Vitals", "LCP", "CLS", "INP",
|
|
11
|
+
"render-blocking", "bundle size", "code splitting", "lazy loading", "cache headers",
|
|
12
|
+
"performance budget", "ускорить сайт", "медленно грузится", "оптимизация скорости", "вес
|
|
13
|
+
бандла". Not for visual design or conversion work.
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# Frontend Performance
|
|
17
|
+
|
|
18
|
+
Optimize frontend applications for maximum Lighthouse scores and real-user performance. This skill covers the technical performance layer -- for visual design, see `frontend-design`; for conversion optimization, see `landing-page-design`.
|
|
19
|
+
|
|
20
|
+
## Audit Workflow
|
|
21
|
+
|
|
22
|
+
1. **Measure** -- Run PageSpeed Insights or Lighthouse. Record scores and failing audits.
|
|
23
|
+
2. **Diagnose** -- Map each failing audit to a specific code-level cause (see checklist below).
|
|
24
|
+
3. **Prioritize** -- Fix by impact: P0 blocks rendering, P1 hurts metrics, P2 is informational.
|
|
25
|
+
4. **Implement** -- Apply fixes per the reference guides.
|
|
26
|
+
5. **Validate** -- `next build` (or framework equivalent) + re-run Lighthouse. Verify no regressions.
|
|
27
|
+
|
|
28
|
+
## Core Web Vitals Targets
|
|
29
|
+
|
|
30
|
+
| Metric | Good | Needs Work | Poor |
|
|
31
|
+
|--------|------|------------|------|
|
|
32
|
+
| LCP (Largest Contentful Paint) | < 2.5s | 2.5-4.0s | > 4.0s |
|
|
33
|
+
| INP (Interaction to Next Paint) | < 200ms | 200-500ms | > 500ms |
|
|
34
|
+
| CLS (Cumulative Layout Shift) | < 0.1 | 0.1-0.25 | > 0.25 |
|
|
35
|
+
| FCP (First Contentful Paint) | < 1.8s | 1.8-3.0s | > 3.0s |
|
|
36
|
+
| TBT (Total Blocking Time) | < 200ms | 200-600ms | > 600ms |
|
|
37
|
+
| SI (Speed Index) | < 3.4s | 3.4-5.8s | > 5.8s |
|
|
38
|
+
|
|
39
|
+
## Performance Checklist
|
|
40
|
+
|
|
41
|
+
### Fonts (LCP, FCP)
|
|
42
|
+
|
|
43
|
+
- **Self-host fonts** -- Never load from external CDNs via `<link>` tags. Use framework font optimization (`next/font/google`, `@fontsource`, etc.) to inline CSS and self-host files.
|
|
44
|
+
- **Preload critical fonts** -- The font used by the LCP element must load early.
|
|
45
|
+
- **Limit font families** -- Max 3 families. Each family adds ~20-50KB.
|
|
46
|
+
- **Subset fonts** -- Only load needed character sets (`latin`, `latin-ext`).
|
|
47
|
+
- **Use `font-display: swap`** -- Prevents invisible text during load (FOIT).
|
|
48
|
+
- **Remove unused preconnects** -- If fonts are self-hosted, `preconnect` to font CDNs is dead weight.
|
|
49
|
+
|
|
50
|
+
### JavaScript (TBT, FCP, LCP)
|
|
51
|
+
|
|
52
|
+
- **Code split aggressively** -- Lazy-load below-the-fold sections. Only hero + nav in initial bundle.
|
|
53
|
+
- **Defer third-party scripts** -- GA, analytics, chat widgets load after interactive (`afterInteractive` or `defer`).
|
|
54
|
+
- **Target modern browsers** -- Set `browserslist` to avoid shipping polyfills for `Array.prototype.at`, `Object.fromEntries`, etc.:
|
|
55
|
+
```
|
|
56
|
+
last 2 Chrome versions, last 2 Firefox versions, last 2 Safari versions, last 2 Edge versions
|
|
57
|
+
```
|
|
58
|
+
- **Tree-shake imports** -- Named imports only. No `import * as`.
|
|
59
|
+
- **Analyze bundles** -- Use `@next/bundle-analyzer`, `source-map-explorer`, or `vite-plugin-visualizer`.
|
|
60
|
+
|
|
61
|
+
### CSS & Animations (CLS)
|
|
62
|
+
|
|
63
|
+
- **Composite-only animations** -- Only animate `transform` and `opacity` (GPU-composited). Never animate `background-position`, `width`, `height`, `top/left`, `margin`, `padding`.
|
|
64
|
+
- **Use `will-change` sparingly** -- Add `will-change: transform` or `will-change: filter` only on elements that actually animate.
|
|
65
|
+
- **Inline critical CSS** -- Framework should handle this (Next.js does automatically).
|
|
66
|
+
- **Avoid layout shifts** -- Set explicit `width`/`height` on images and embeds. Reserve space for dynamic content.
|
|
67
|
+
|
|
68
|
+
### Images (LCP, CLS)
|
|
69
|
+
|
|
70
|
+
- **Use `<Image>` component** -- Framework-optimized components (`next/image`, Astro `<Image>`) auto-resize, convert to WebP/AVIF, and add `width`/`height`.
|
|
71
|
+
- **Priority-load LCP image** -- Add `priority` (Next.js) or `fetchpriority="high"` to the hero/LCP image.
|
|
72
|
+
- **Lazy-load below-fold** -- All images below the initial viewport get `loading="lazy"`.
|
|
73
|
+
- **Size budget**: Hero < 200KB, thumbnails < 50KB, icons as SVG.
|
|
74
|
+
- **Responsive `sizes`** -- Always provide `sizes` attribute for responsive images.
|
|
75
|
+
|
|
76
|
+
### Caching (Repeat Visits)
|
|
77
|
+
|
|
78
|
+
- **Static assets**: `Cache-Control: public, max-age=31536000, immutable` for hashed files (JS, CSS, fonts, images).
|
|
79
|
+
- **HTML**: `Cache-Control: public, max-age=0, must-revalidate` (or framework default).
|
|
80
|
+
- **Verify patterns** -- Test cache header `source` patterns against actual URLs. Common mistake: glob-style patterns (`{.svg,.png}`) don't work in all frameworks' path-matching (e.g., Next.js uses `path-to-regexp`). Use regex parameter syntax instead:
|
|
81
|
+
```
|
|
82
|
+
/:path*.:ext(svg|png|jpg|jpeg|gif|webp|ico|woff|woff2)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Content Security Policy (Best Practices)
|
|
86
|
+
|
|
87
|
+
- **Whitelist all loaded origins** -- CSP blocks = console errors = lower Best Practices score.
|
|
88
|
+
- **Audit after every third-party change** -- Adding analytics, fonts, or CDN scripts requires CSP updates.
|
|
89
|
+
- **Tighten after migration** -- If you move from external fonts to self-hosted, remove the old CSP entries.
|
|
90
|
+
- **Common CSP origins**:
|
|
91
|
+
- Google Analytics: `https://www.googletagmanager.com`, `https://www.google-analytics.com`
|
|
92
|
+
- Cloudflare: `https://static.cloudflareinsights.com`
|
|
93
|
+
- Stripe: `https://js.stripe.com`
|
|
94
|
+
|
|
95
|
+
### Accessibility (Lighthouse A11y Score)
|
|
96
|
+
|
|
97
|
+
These directly affect the Lighthouse Accessibility score:
|
|
98
|
+
|
|
99
|
+
- **Contrast ratio** -- WCAG AA requires 4.5:1 for normal text, 3:1 for large text. Avoid opacity modifiers on text colors (e.g., `text-primary/80` in Tailwind reduces contrast). Use full-opacity color tokens.
|
|
100
|
+
- **Heading hierarchy** -- Sequential: `h1` -> `h2` -> `h3`. Never skip levels. Use non-heading elements (`<p>`) for visual-only "headings" (e.g., footer column titles).
|
|
101
|
+
- **Alt text** -- Decorative images next to identical text get `alt=""`. Informative images get descriptive alt. Never duplicate adjacent text.
|
|
102
|
+
- **Tap targets** -- Minimum 48x48px on mobile. Applies to buttons, links, form inputs.
|
|
103
|
+
|
|
104
|
+
## Framework-Specific Guides
|
|
105
|
+
|
|
106
|
+
- **Next.js**: See [references/nextjs.md](references/nextjs.md) for `next/font`, `next/image`, `next/dynamic`, `next/script`, cache headers in `next.config`, CSP configuration, and bundle analysis.
|
|
107
|
+
- **CSS/Animation**: See [references/css-performance.md](references/css-performance.md) for compositing rules, gradient animation alternatives, `will-change` usage, and critical CSS strategies.
|
|
108
|
+
- **Accessibility**: See [references/accessibility-perf.md](references/accessibility-perf.md) for contrast calculations, heading hierarchy rules, and ARIA patterns that affect Lighthouse.
|
|
109
|
+
|
|
110
|
+
## Common PageSpeed Failures & Fixes
|
|
111
|
+
|
|
112
|
+
| Audit | Cause | Fix |
|
|
113
|
+
|-------|-------|-----|
|
|
114
|
+
| "Eliminate render-blocking resources" | External font CSS, large CSS files | Self-host fonts, inline critical CSS |
|
|
115
|
+
| "Reduce unused JavaScript" | Full page bundle loaded upfront | Code-split with dynamic imports |
|
|
116
|
+
| "Avoid non-composited animations" | Animating `background-position`, `width`, etc. | Replace with `transform`/`opacity`/`filter` |
|
|
117
|
+
| "Serve static assets with efficient cache policy" | Missing or short `Cache-Control` headers | Set `max-age=31536000, immutable` for hashed assets |
|
|
118
|
+
| "Background/foreground colors do not have sufficient contrast" | Opacity modifiers on text colors | Use full-opacity color tokens |
|
|
119
|
+
| "Heading elements not in sequential order" | Skipped heading levels (h1 -> h4) | Fix hierarchy or use `<p>` for non-structural headings |
|
|
120
|
+
| "Browser errors logged to console" | CSP blocking scripts/styles | Whitelist required origins in CSP |
|
|
121
|
+
| "Image elements do not have [alt] attributes" | Missing or redundant alt text | Add descriptive alt, or `alt=""` for decorative |
|
|
122
|
+
| "Avoid chaining critical requests" | Waterfall of blocking resources | Preload critical resources, self-host |
|
|
123
|
+
| "Legacy JavaScript" | Polyfills for modern APIs | Update `browserslist` targets |
|
|
124
|
+
|
|
125
|
+
## Performance Budget Template
|
|
126
|
+
|
|
127
|
+
Set these limits for landing pages:
|
|
128
|
+
|
|
129
|
+
| Resource | Budget |
|
|
130
|
+
|----------|--------|
|
|
131
|
+
| Total page weight | < 1.5 MB |
|
|
132
|
+
| JavaScript (compressed) | < 200 KB |
|
|
133
|
+
| CSS (compressed) | < 50 KB |
|
|
134
|
+
| Fonts (total) | < 150 KB |
|
|
135
|
+
| Hero image | < 200 KB |
|
|
136
|
+
| LCP | < 2.5s (mobile) |
|
|
137
|
+
| FCP | < 1.8s (mobile) |
|
|
138
|
+
| CLS | < 0.1 |
|
|
139
|
+
| TBT | < 200ms |
|
|
140
|
+
|
|
141
|
+
## Related Skills
|
|
142
|
+
|
|
143
|
+
- `frontend-design` -- Visual aesthetics and UI design
|
|
144
|
+
- `landing-page-design` -- Conversion optimization and layout
|
|
145
|
+
- `next-best-practices` -- Next.js framework patterns
|
|
146
|
+
- `seo-audit` -- Technical SEO and crawlability
|
|
147
|
+
- `responsive-design` -- Adaptive layouts and container queries
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# Accessibility Rules That Affect Lighthouse Score
|
|
2
|
+
|
|
3
|
+
These accessibility issues are automatically detected by Lighthouse and directly reduce the Accessibility score.
|
|
4
|
+
|
|
5
|
+
## Contents
|
|
6
|
+
|
|
7
|
+
- [Color Contrast](#color-contrast)
|
|
8
|
+
- [Heading Hierarchy](#heading-hierarchy)
|
|
9
|
+
- [Image Alt Text](#image-alt-text)
|
|
10
|
+
- [Interactive Element Sizing](#interactive-element-sizing)
|
|
11
|
+
- [Focus Indicators](#focus-indicators)
|
|
12
|
+
- [ARIA Landmarks](#aria-landmarks)
|
|
13
|
+
- [Language Attribute](#language-attribute)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## Color Contrast
|
|
17
|
+
|
|
18
|
+
### WCAG AA Requirements
|
|
19
|
+
|
|
20
|
+
| Text Type | Minimum Ratio | Example |
|
|
21
|
+
|-----------|--------------|---------|
|
|
22
|
+
| Normal text (< 18px or < 14px bold) | 4.5:1 | Body copy, labels, section headers |
|
|
23
|
+
| Large text (>= 18px or >= 14px bold) | 3:1 | Headings, hero text |
|
|
24
|
+
| UI components & graphical objects | 3:1 | Buttons, icons, form borders |
|
|
25
|
+
|
|
26
|
+
### Common Failures in Dark Themes
|
|
27
|
+
|
|
28
|
+
Dark themes are the most common source of contrast failures because designers use opacity to create visual hierarchy:
|
|
29
|
+
|
|
30
|
+
| Pattern | Problem | Fix |
|
|
31
|
+
|---------|---------|-----|
|
|
32
|
+
| `text-primary/80` | 80% opacity reduces contrast below 4.5:1 | Use `text-primary` (full opacity) |
|
|
33
|
+
| `text-muted-foreground/60` | 60% opacity on already-muted color | Use `text-muted-foreground` |
|
|
34
|
+
| `text-white/60` on dark bg | Insufficient contrast | Use `text-white/80` minimum, test with tool |
|
|
35
|
+
| `text-gray-400` on `bg-gray-900` | May or may not pass depending on exact values | Test with contrast checker |
|
|
36
|
+
|
|
37
|
+
### Tailwind Opacity vs Dedicated Color Tokens
|
|
38
|
+
|
|
39
|
+
**Bad (Lighthouse failure):**
|
|
40
|
+
```html
|
|
41
|
+
<p class="text-primary/80">Section Label</p>
|
|
42
|
+
<span class="text-muted-foreground/60">Subtitle</span>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Good:**
|
|
46
|
+
```html
|
|
47
|
+
<p class="text-primary">Section Label</p>
|
|
48
|
+
<span class="text-muted-foreground">Subtitle</span>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
If you need visual hierarchy without reducing contrast below WCAG thresholds:
|
|
52
|
+
- Use `font-weight` differences (semibold vs regular)
|
|
53
|
+
- Use `font-size` differences (sm vs xs)
|
|
54
|
+
- Use `letter-spacing` and `uppercase` for labels
|
|
55
|
+
- Use a dedicated lighter color token that still passes contrast (e.g., define `--muted-accent` that's tested for 4.5:1)
|
|
56
|
+
|
|
57
|
+
### Checking Contrast
|
|
58
|
+
|
|
59
|
+
Use Chrome DevTools: inspect element -> color picker shows contrast ratio against computed background.
|
|
60
|
+
|
|
61
|
+
Or calculate manually: `(L1 + 0.05) / (L2 + 0.05)` where L1 is the lighter relative luminance.
|
|
62
|
+
|
|
63
|
+
### Intentional Low-Contrast Exceptions
|
|
64
|
+
|
|
65
|
+
Some design systems (cyberpunk, neon, etc.) intentionally use low-contrast text as an aesthetic choice (`text-cyan-400/60`, `text-white/40`). These should:
|
|
66
|
+
- Be reviewed with visual testing, not bulk-replaced
|
|
67
|
+
- Only be used on decorative, non-essential text
|
|
68
|
+
- Never be used on actionable elements (buttons, links, form labels)
|
|
69
|
+
|
|
70
|
+
## Heading Hierarchy
|
|
71
|
+
|
|
72
|
+
### Rules
|
|
73
|
+
|
|
74
|
+
1. **One `<h1>` per page** -- typically the main page title or hero headline.
|
|
75
|
+
2. **Sequential descent** -- `h1` -> `h2` -> `h3` -> `h4`. Never skip levels.
|
|
76
|
+
3. **Non-structural "headings"** use `<p>` or `<span>` -- footer column titles, sidebar labels, card subtitles are not document headings.
|
|
77
|
+
|
|
78
|
+
### Common Violations
|
|
79
|
+
|
|
80
|
+
| Location | Violation | Fix |
|
|
81
|
+
|----------|-----------|-----|
|
|
82
|
+
| Footer column titles as `<h4>` | h1 -> h2 -> h4 (skips h3) | Change to `<p class="font-semibold text-xs uppercase ...">` |
|
|
83
|
+
| Multiple `<h1>` per page | Each section has its own h1 | Use `<h2>` for section titles |
|
|
84
|
+
| Card titles as `<h3>` inside a section with no `<h2>` | Heading skip | Wrap cards in a section with an `<h2>` |
|
|
85
|
+
|
|
86
|
+
### Screen Reader Impact
|
|
87
|
+
|
|
88
|
+
Screen reader users navigate by heading level. Skipped levels break expected navigation patterns and confuse the document outline.
|
|
89
|
+
|
|
90
|
+
## Image Alt Text
|
|
91
|
+
|
|
92
|
+
### Decision Tree
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
Is the image decorative (purely visual, no information)?
|
|
96
|
+
├── YES → alt=""
|
|
97
|
+
│ Examples: background patterns, decorative borders, logos next to brand text
|
|
98
|
+
└── NO → Write descriptive alt text
|
|
99
|
+
├── Is it informative? → Describe the content
|
|
100
|
+
│ Example: alt="Dashboard showing 50% growth in monthly users"
|
|
101
|
+
├── Is it functional (link/button)? → Describe the action
|
|
102
|
+
│ Example: alt="Download PDF report"
|
|
103
|
+
└── Is it complex (chart/diagram)? → Summarize + provide long description
|
|
104
|
+
Example: alt="Sales trend chart" + aria-describedby for details
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Redundancy Rule
|
|
108
|
+
|
|
109
|
+
If an image appears next to text that says the same thing, the image is decorative:
|
|
110
|
+
|
|
111
|
+
**Bad (screen reader announces "PrivateClawd" twice):**
|
|
112
|
+
```html
|
|
113
|
+
<img alt="PrivateClawd" src="/logo.svg" />
|
|
114
|
+
<span>PrivateClawd</span>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Good:**
|
|
118
|
+
```html
|
|
119
|
+
<img alt="" src="/logo.svg" />
|
|
120
|
+
<span>PrivateClawd</span>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Interactive Element Sizing
|
|
124
|
+
|
|
125
|
+
Minimum tap target: **48x48px** (Google), **44x44px** (Apple HIG).
|
|
126
|
+
|
|
127
|
+
```css
|
|
128
|
+
/* Ensure minimum tap target even for small visual buttons */
|
|
129
|
+
.icon-button {
|
|
130
|
+
min-width: 44px;
|
|
131
|
+
min-height: 44px;
|
|
132
|
+
display: inline-flex;
|
|
133
|
+
align-items: center;
|
|
134
|
+
justify-content: center;
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Adjacent tap targets need at least 8px spacing to prevent accidental taps.
|
|
139
|
+
|
|
140
|
+
## Focus Indicators
|
|
141
|
+
|
|
142
|
+
Lighthouse checks for visible focus indicators on interactive elements:
|
|
143
|
+
|
|
144
|
+
```css
|
|
145
|
+
/* Never remove focus outlines without replacement */
|
|
146
|
+
:focus-visible {
|
|
147
|
+
outline: 2px solid var(--ring);
|
|
148
|
+
outline-offset: 2px;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/* Bad -- removes accessibility */
|
|
152
|
+
*:focus { outline: none; }
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## ARIA Landmarks
|
|
156
|
+
|
|
157
|
+
Ensure the page has proper landmark regions. Lighthouse checks for:
|
|
158
|
+
|
|
159
|
+
- `<main>` -- one per page, wrapping primary content
|
|
160
|
+
- `<nav>` -- navigation regions
|
|
161
|
+
- `<header>` / `<footer>` -- page header and footer
|
|
162
|
+
- `role="search"` on search forms
|
|
163
|
+
|
|
164
|
+
Landmarks enable screen reader users to jump between page sections.
|
|
165
|
+
|
|
166
|
+
## Language Attribute
|
|
167
|
+
|
|
168
|
+
```html
|
|
169
|
+
<html lang="en">
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Always set the `lang` attribute on `<html>`. Lighthouse flags its absence. Use the correct BCP 47 language tag for the page's primary language.
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# CSS & Animation Performance
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## Contents
|
|
5
|
+
|
|
6
|
+
- [GPU-Composited Properties](#gpu-composited-properties)
|
|
7
|
+
- [Gradient Animation Alternatives](#gradient-animation-alternatives)
|
|
8
|
+
- [`will-change` Usage](#will-change-usage)
|
|
9
|
+
- [Critical CSS](#critical-css)
|
|
10
|
+
- [Layout Shift Prevention](#layout-shift-prevention)
|
|
11
|
+
- [Tailwind CSS Performance](#tailwind-css-performance)
|
|
12
|
+
|
|
13
|
+
## GPU-Composited Properties
|
|
14
|
+
|
|
15
|
+
The browser can animate these properties on the GPU compositor thread without triggering layout or paint:
|
|
16
|
+
|
|
17
|
+
| Property | GPU-composited | Use For |
|
|
18
|
+
|----------|---------------|---------|
|
|
19
|
+
| `transform` | Yes | Movement, scaling, rotation |
|
|
20
|
+
| `opacity` | Yes | Fading in/out |
|
|
21
|
+
| `filter` | Yes (most browsers) | Blur, hue-rotate, brightness |
|
|
22
|
+
| `background-position` | **No** | Avoid animating |
|
|
23
|
+
| `width` / `height` | **No** | Avoid animating |
|
|
24
|
+
| `top` / `left` / `right` / `bottom` | **No** | Use `transform: translate()` instead |
|
|
25
|
+
| `margin` / `padding` | **No** | Avoid animating |
|
|
26
|
+
| `border-radius` | **No** | Avoid animating |
|
|
27
|
+
| `box-shadow` | **No** | Use `opacity` on a pseudo-element instead |
|
|
28
|
+
| `color` / `background-color` | **No** | Pre-render both states, animate `opacity` |
|
|
29
|
+
|
|
30
|
+
Animating non-composited properties triggers layout recalculation and paint on every frame, causing jank and increasing CLS.
|
|
31
|
+
|
|
32
|
+
## Gradient Animation Alternatives
|
|
33
|
+
|
|
34
|
+
### Problem: Animated `background-position`
|
|
35
|
+
|
|
36
|
+
```css
|
|
37
|
+
/* BAD -- triggers paint on every frame */
|
|
38
|
+
@keyframes gradient-shift {
|
|
39
|
+
0% { background-position: 0% 50%; }
|
|
40
|
+
50% { background-position: 100% 50%; }
|
|
41
|
+
100% { background-position: 0% 50%; }
|
|
42
|
+
}
|
|
43
|
+
.animate-gradient {
|
|
44
|
+
background-size: 200% 200%;
|
|
45
|
+
animation: gradient-shift 6s ease infinite;
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This is flagged by Lighthouse as "non-composited animation" because `background-position` cannot be GPU-composited.
|
|
50
|
+
|
|
51
|
+
### Fix Option A: `filter: hue-rotate()` (recommended)
|
|
52
|
+
|
|
53
|
+
```css
|
|
54
|
+
@keyframes gradient-shift {
|
|
55
|
+
0%, 100% { filter: hue-rotate(0deg); }
|
|
56
|
+
50% { filter: hue-rotate(30deg); }
|
|
57
|
+
}
|
|
58
|
+
.animate-gradient {
|
|
59
|
+
animation: gradient-shift 6s ease infinite;
|
|
60
|
+
will-change: filter;
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Pros: GPU-composited, subtle color variation, minimal code change.
|
|
65
|
+
Cons: Shifts all colors (not just the gradient), effect is different from background-position scrolling.
|
|
66
|
+
|
|
67
|
+
### Fix Option B: Transform on pseudo-element
|
|
68
|
+
|
|
69
|
+
```css
|
|
70
|
+
.animate-gradient {
|
|
71
|
+
position: relative;
|
|
72
|
+
overflow: hidden;
|
|
73
|
+
}
|
|
74
|
+
.animate-gradient::before {
|
|
75
|
+
content: "";
|
|
76
|
+
position: absolute;
|
|
77
|
+
inset: 0;
|
|
78
|
+
background: linear-gradient(to right, #a855f7, #d946ef, #a855f7);
|
|
79
|
+
background-size: 200% 100%;
|
|
80
|
+
animation: gradient-slide 6s ease infinite;
|
|
81
|
+
will-change: transform;
|
|
82
|
+
z-index: -1;
|
|
83
|
+
}
|
|
84
|
+
@keyframes gradient-slide {
|
|
85
|
+
0%, 100% { transform: translateX(0); }
|
|
86
|
+
50% { transform: translateX(-50%); }
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Pros: True sliding gradient, fully GPU-composited.
|
|
91
|
+
Cons: More complex markup, doesn't work with `bg-clip-text`.
|
|
92
|
+
|
|
93
|
+
### Fix Option C: Remove animation
|
|
94
|
+
|
|
95
|
+
```css
|
|
96
|
+
.animate-gradient {
|
|
97
|
+
/* Static gradient, no animation */
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Simplest fix. Use when the animation is subtle and non-essential.
|
|
102
|
+
|
|
103
|
+
## `will-change` Usage
|
|
104
|
+
|
|
105
|
+
`will-change` hints the browser to promote an element to its own compositor layer.
|
|
106
|
+
|
|
107
|
+
**Rules:**
|
|
108
|
+
- Only add to elements that actually animate
|
|
109
|
+
- Remove after animation completes (for one-shot animations)
|
|
110
|
+
- Never use `will-change: auto` (it's the default, useless)
|
|
111
|
+
- Never apply to more than a few elements -- each promoted layer uses GPU memory
|
|
112
|
+
|
|
113
|
+
```css
|
|
114
|
+
/* Good -- only on animated elements */
|
|
115
|
+
.animate-gradient { will-change: filter; }
|
|
116
|
+
.slide-in { will-change: transform; }
|
|
117
|
+
|
|
118
|
+
/* Bad -- blanket application */
|
|
119
|
+
* { will-change: transform; }
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Critical CSS
|
|
123
|
+
|
|
124
|
+
### Framework Handling
|
|
125
|
+
|
|
126
|
+
Most modern frameworks handle critical CSS automatically:
|
|
127
|
+
- **Next.js**: Inlines CSS for initial render via built-in optimization
|
|
128
|
+
- **Astro**: Scoped styles are inlined per-component
|
|
129
|
+
- **Vite/SvelteKit**: CSS is extracted and linked efficiently
|
|
130
|
+
|
|
131
|
+
### Manual Optimization
|
|
132
|
+
|
|
133
|
+
If the framework doesn't handle it:
|
|
134
|
+
|
|
135
|
+
1. Extract CSS used by above-the-fold elements
|
|
136
|
+
2. Inline it in `<style>` within `<head>`
|
|
137
|
+
3. Load remaining CSS asynchronously:
|
|
138
|
+
```html
|
|
139
|
+
<link rel="preload" href="/styles.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
|
|
140
|
+
<noscript><link rel="stylesheet" href="/styles.css"></noscript>
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Layout Shift Prevention
|
|
144
|
+
|
|
145
|
+
| Element | Fix |
|
|
146
|
+
|---------|-----|
|
|
147
|
+
| Images | Always set `width` and `height` attributes |
|
|
148
|
+
| Embeds/iframes | Set explicit dimensions or use `aspect-ratio` |
|
|
149
|
+
| Dynamic content | Reserve space with `min-height` |
|
|
150
|
+
| Web fonts | Use `font-display: swap` + size-adjusted fallback |
|
|
151
|
+
| Ads/banners | Reserve slot with fixed dimensions |
|
|
152
|
+
| Sticky headers | Account for height with `scroll-padding-top` |
|
|
153
|
+
|
|
154
|
+
### Font CLS Mitigation
|
|
155
|
+
|
|
156
|
+
When fonts swap from fallback to web font, text reflows and causes CLS. Mitigate with:
|
|
157
|
+
|
|
158
|
+
```css
|
|
159
|
+
/* Size-adjust the fallback to match the web font */
|
|
160
|
+
@font-face {
|
|
161
|
+
font-family: "Fallback";
|
|
162
|
+
src: local("Arial");
|
|
163
|
+
size-adjust: 105%;
|
|
164
|
+
ascent-override: 95%;
|
|
165
|
+
descent-override: 22%;
|
|
166
|
+
line-gap-override: 0%;
|
|
167
|
+
}
|
|
168
|
+
body {
|
|
169
|
+
font-family: "YourWebFont", "Fallback", sans-serif;
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
`next/font` does this automatically when you use the `variable` option.
|
|
174
|
+
|
|
175
|
+
## Tailwind CSS Performance
|
|
176
|
+
|
|
177
|
+
- **Purge unused classes** -- Tailwind v3+ does this automatically in production. Ensure `content` paths cover all template files.
|
|
178
|
+
- **Avoid runtime class generation** -- Never use string interpolation for Tailwind classes (`text-${color}-500`). Tailwind can't detect these at build time.
|
|
179
|
+
- **Opacity modifiers and contrast** -- `text-primary/80` creates 80% opacity, which may fail WCAG contrast. Prefer full-opacity tokens for text, use opacity only on decorative elements.
|
|
180
|
+
- **Minimize `@apply`** -- Excessive `@apply` bloats CSS. Use component composition instead.
|