gral-frontend-skill 1.0.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/LICENSE +21 -0
- package/README.md +184 -0
- package/bin/install.js +186 -0
- package/commands/affina.md +257 -0
- package/commands/allinea.md +66 -0
- package/commands/anima.md +171 -0
- package/commands/ardore.md +112 -0
- package/commands/carattere.md +111 -0
- package/commands/componi.md +120 -0
- package/commands/distilla.md +117 -0
- package/commands/forgia.md +91 -0
- package/commands/incanto.md +282 -0
- package/commands/inizia.md +239 -0
- package/commands/lucida.md +199 -0
- package/commands/lume.md +179 -0
- package/commands/magistero.md +339 -0
- package/commands/muta.md +195 -0
- package/commands/scrutinio.md +145 -0
- package/commands/smorza.md +98 -0
- package/commands/tempra.md +343 -0
- package/commands/tinta.md +139 -0
- package/package.json +34 -0
- package/reference/color-and-contrast.md +105 -0
- package/reference/craft.md +70 -0
- package/reference/interaction-design.md +195 -0
- package/reference/motion-design.md +99 -0
- package/reference/responsive-design.md +114 -0
- package/reference/spatial-design.md +100 -0
- package/reference/typography.md +142 -0
- package/reference/ux-writing.md +107 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 gral-digital
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# Frontend Design Skills for Claude Code
|
|
2
|
+
|
|
3
|
+
A system of 18 specialized slash commands that give Claude Code deep expertise in frontend design and UI/UX engineering. Each command targets a specific aspect of interface quality — from typography and layout to performance and accessibility.
|
|
4
|
+
|
|
5
|
+
These are not generic prompts. They encode opinionated, production-grade design knowledge: anti-pattern detection, AI slop avoidance, WCAG compliance, and the kind of attention to detail that separates shipped from polished.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Make sure you have [Claude Code](https://docs.anthropic.com/en/docs/claude-code) and Node.js installed, then run:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npx gral-frontend-skill
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
That's it. The installer copies 18 commands and 8 reference files to `~/.claude/` so they're available in every Claude Code session.
|
|
16
|
+
|
|
17
|
+
### First-time project setup
|
|
18
|
+
|
|
19
|
+
In any project where you want to use these skills, open Claude Code and run:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
/user:magistero teach
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Claude will interview you about your project's audience, brand personality, and aesthetic direction, then save a `.design-context.md` file in the project root. All other commands use this file to produce context-aware results instead of generic output.
|
|
26
|
+
|
|
27
|
+
You only need to do this **once per project**. If you skip it, commands will ask you to do it first.
|
|
28
|
+
|
|
29
|
+
### Project-level installation
|
|
30
|
+
|
|
31
|
+
If you want the skills available only inside a specific project (instead of globally), run the installer from the project root with the `--project` flag:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npx gral-frontend-skill --project
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
This copies everything to `.claude/commands/` and `.claude/reference/` within the current directory, and automatically rewrites internal paths. Commands become available as `/project:command-name`.
|
|
38
|
+
|
|
39
|
+
### Updating
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx gral-frontend-skill@latest
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Uninstalling
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npx gral-frontend-skill --uninstall
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Commands
|
|
54
|
+
|
|
55
|
+
### Foundation
|
|
56
|
+
|
|
57
|
+
| Command | What it does |
|
|
58
|
+
|---------|-------------|
|
|
59
|
+
| **magistero** | Core design skill. Contains all design principles, anti-patterns, font selection procedure, and the AI Slop Test. Modes: `teach` (setup), `craft` (full build flow), or default (design creation). |
|
|
60
|
+
| **forgia** | Plans UX/UI before code. Runs a discovery interview and produces a structured design brief. |
|
|
61
|
+
|
|
62
|
+
### Building
|
|
63
|
+
|
|
64
|
+
| Command | What it does |
|
|
65
|
+
|---------|-------------|
|
|
66
|
+
| **carattere** | Typography — font choices, hierarchy, scale, weight, readability |
|
|
67
|
+
| **componi** | Layout & spacing — grid, rhythm, visual hierarchy, density |
|
|
68
|
+
| **tinta** | Color — strategic palette, semantic color, OKLCH, accessibility |
|
|
69
|
+
| **anima** | Animation — micro-interactions, entrance choreography, easing, reduced motion |
|
|
70
|
+
| **muta** | Responsive — cross-device adaptation, touch targets, breakpoints |
|
|
71
|
+
| **lume** | UX writing — error messages, labels, microcopy, empty states |
|
|
72
|
+
| **incanto** | Delight — personality, easter eggs, celebrations, loading states |
|
|
73
|
+
| **inizia** | Onboarding — first-run experience, empty states, progressive disclosure |
|
|
74
|
+
|
|
75
|
+
### Tuning
|
|
76
|
+
|
|
77
|
+
| Command | What it does |
|
|
78
|
+
|---------|-------------|
|
|
79
|
+
| **ardore** | Amplify — make safe/boring designs more impactful and memorable |
|
|
80
|
+
| **smorza** | Tone down — reduce aggressive/overstimulating designs to refined |
|
|
81
|
+
| **distilla** | Simplify — strip to essence, remove unnecessary complexity |
|
|
82
|
+
|
|
83
|
+
### Hardening
|
|
84
|
+
|
|
85
|
+
| Command | What it does |
|
|
86
|
+
|---------|-------------|
|
|
87
|
+
| **affina** | Performance — loading speed, rendering, bundle size, Core Web Vitals |
|
|
88
|
+
| **tempra** | Resilience — error handling, i18n, text overflow, edge cases |
|
|
89
|
+
| **allinea** | Design system — realign to tokens, patterns, and standards |
|
|
90
|
+
|
|
91
|
+
### Quality
|
|
92
|
+
|
|
93
|
+
| Command | What it does |
|
|
94
|
+
|---------|-------------|
|
|
95
|
+
| **scrutinio** | Audit — scored technical report (a11y, perf, theming, responsive, anti-patterns) with P0-P3 severity |
|
|
96
|
+
| **lucida** | Polish — final pass on alignment, spacing, states, transitions, code quality |
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Typical Workflows
|
|
101
|
+
|
|
102
|
+
### New feature (full process)
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
/user:magistero teach → establish design context (once per project)
|
|
106
|
+
/user:forgia → discovery interview + design brief
|
|
107
|
+
/user:magistero craft → build with visual iteration
|
|
108
|
+
/user:scrutinio → technical audit
|
|
109
|
+
/user:lucida → final polish
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Improve existing UI
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
/user:scrutinio → find what's wrong (scored report)
|
|
116
|
+
/user:carattere → fix typography
|
|
117
|
+
/user:componi → fix layout/spacing
|
|
118
|
+
/user:tinta → fix color
|
|
119
|
+
/user:lucida → final polish
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Make it bolder / quieter
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
/user:ardore → amplify bland designs
|
|
126
|
+
/user:smorza → tone down aggressive designs
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Production hardening
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
/user:tempra → edge cases, i18n, error states
|
|
133
|
+
/user:affina → performance optimization
|
|
134
|
+
/user:allinea → design system alignment
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Reference Files
|
|
140
|
+
|
|
141
|
+
Commands automatically consult these when they need deeper technical material:
|
|
142
|
+
|
|
143
|
+
| File | Content |
|
|
144
|
+
|------|---------|
|
|
145
|
+
| `typography.md` | Type scales, font pairing, OpenType features, web font loading |
|
|
146
|
+
| `spatial-design.md` | Spacing systems, grid, container queries, optical adjustments |
|
|
147
|
+
| `color-and-contrast.md` | OKLCH, palette construction, WCAG contrast, dark mode |
|
|
148
|
+
| `motion-design.md` | Duration/easing tables, reduced motion, perceived performance |
|
|
149
|
+
| `interaction-design.md` | 8 interactive states, focus rings, forms, popovers, keyboard nav |
|
|
150
|
+
| `responsive-design.md` | Mobile-first, input detection, safe areas, responsive images |
|
|
151
|
+
| `ux-writing.md` | Button labels, error formulas, empty states, translation |
|
|
152
|
+
| `craft.md` | The full forgia→build→iterate→present workflow |
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## How Commands Work Together
|
|
157
|
+
|
|
158
|
+
All design commands share a dependency on **magistero**, which provides:
|
|
159
|
+
|
|
160
|
+
- The **Context Gathering Protocol** — ensures design context exists before any work
|
|
161
|
+
- **Design principles** — typography, color, layout, motion, interaction rules
|
|
162
|
+
- **Anti-pattern detection** — the AI Slop Test and absolute bans (gradient text, side-stripe borders, glassmorphism)
|
|
163
|
+
- **Font selection procedure** — a structured process to avoid training-data monoculture
|
|
164
|
+
|
|
165
|
+
When you run any command, it first checks for `.design-context.md` in your project root (created by `/magistero teach`), then reads magistero's principles. This ensures consistent quality across all commands.
|
|
166
|
+
|
|
167
|
+
**scrutinio** is the diagnostic command — it audits without fixing, producing a scored report that maps issues to the appropriate fix commands. Run it before and after changes to track improvement.
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Manual Installation
|
|
172
|
+
|
|
173
|
+
If you prefer not to use npx, you can clone and copy manually:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
git clone https://github.com/gral-digital/frontend-skill.git
|
|
177
|
+
cp frontend-skill/commands/*.md ~/.claude/commands/
|
|
178
|
+
mkdir -p ~/.claude/reference
|
|
179
|
+
cp frontend-skill/reference/*.md ~/.claude/reference/
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## License
|
|
183
|
+
|
|
184
|
+
MIT
|
package/bin/install.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const os = require("os");
|
|
6
|
+
|
|
7
|
+
const COMMANDS_DIR_NAME = "commands";
|
|
8
|
+
const REFERENCE_DIR_NAME = "reference";
|
|
9
|
+
const PACKAGE_ROOT = path.resolve(__dirname, "..");
|
|
10
|
+
const CLAUDE_HOME = path.join(os.homedir(), ".claude");
|
|
11
|
+
|
|
12
|
+
const COMMAND_FILES = fs.readdirSync(path.join(PACKAGE_ROOT, COMMANDS_DIR_NAME));
|
|
13
|
+
const REFERENCE_FILES = fs.readdirSync(
|
|
14
|
+
path.join(PACKAGE_ROOT, REFERENCE_DIR_NAME)
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const bold = (t) => `\x1b[1m${t}\x1b[0m`;
|
|
18
|
+
const green = (t) => `\x1b[32m${t}\x1b[0m`;
|
|
19
|
+
const cyan = (t) => `\x1b[36m${t}\x1b[0m`;
|
|
20
|
+
const dim = (t) => `\x1b[2m${t}\x1b[0m`;
|
|
21
|
+
const red = (t) => `\x1b[31m${t}\x1b[0m`;
|
|
22
|
+
|
|
23
|
+
function copyFiles(srcDir, destDir, files, transform) {
|
|
24
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
25
|
+
let count = 0;
|
|
26
|
+
for (const file of files) {
|
|
27
|
+
const src = path.join(srcDir, file);
|
|
28
|
+
const dest = path.join(destDir, file);
|
|
29
|
+
if (transform) {
|
|
30
|
+
const content = fs.readFileSync(src, "utf-8");
|
|
31
|
+
fs.writeFileSync(dest, transform(content), "utf-8");
|
|
32
|
+
} else {
|
|
33
|
+
fs.copyFileSync(src, dest);
|
|
34
|
+
}
|
|
35
|
+
count++;
|
|
36
|
+
}
|
|
37
|
+
return count;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function installGlobal() {
|
|
41
|
+
const commandsDest = path.join(CLAUDE_HOME, "commands");
|
|
42
|
+
const referenceDest = path.join(CLAUDE_HOME, "reference");
|
|
43
|
+
|
|
44
|
+
const cmdCount = copyFiles(
|
|
45
|
+
path.join(PACKAGE_ROOT, COMMANDS_DIR_NAME),
|
|
46
|
+
commandsDest,
|
|
47
|
+
COMMAND_FILES
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const refCount = copyFiles(
|
|
51
|
+
path.join(PACKAGE_ROOT, REFERENCE_DIR_NAME),
|
|
52
|
+
referenceDest,
|
|
53
|
+
REFERENCE_FILES
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
console.log("");
|
|
57
|
+
console.log(green(" ✓ Installed successfully"));
|
|
58
|
+
console.log("");
|
|
59
|
+
console.log(` ${bold(cmdCount)} commands → ${dim(commandsDest)}`);
|
|
60
|
+
console.log(` ${bold(refCount)} references → ${dim(referenceDest)}`);
|
|
61
|
+
console.log("");
|
|
62
|
+
console.log(
|
|
63
|
+
` Commands are now available as ${cyan("/user:command-name")} in Claude Code.`
|
|
64
|
+
);
|
|
65
|
+
console.log("");
|
|
66
|
+
console.log(` ${bold("Next step:")} open Claude Code in a project and run:`);
|
|
67
|
+
console.log("");
|
|
68
|
+
console.log(` ${cyan("/user:magistero teach")}`);
|
|
69
|
+
console.log("");
|
|
70
|
+
console.log(
|
|
71
|
+
dim(" This sets up your project's design context (once per project).")
|
|
72
|
+
);
|
|
73
|
+
console.log("");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function installProject() {
|
|
77
|
+
const projectRoot = process.cwd();
|
|
78
|
+
const commandsDest = path.join(projectRoot, ".claude", "commands");
|
|
79
|
+
const referenceDest = path.join(projectRoot, ".claude", "reference");
|
|
80
|
+
|
|
81
|
+
const rewritePath = (content) =>
|
|
82
|
+
content.replace(/~\/\.claude\/reference\//g, ".claude/reference/");
|
|
83
|
+
|
|
84
|
+
const cmdCount = copyFiles(
|
|
85
|
+
path.join(PACKAGE_ROOT, COMMANDS_DIR_NAME),
|
|
86
|
+
commandsDest,
|
|
87
|
+
COMMAND_FILES,
|
|
88
|
+
rewritePath
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const refCount = copyFiles(
|
|
92
|
+
path.join(PACKAGE_ROOT, REFERENCE_DIR_NAME),
|
|
93
|
+
referenceDest,
|
|
94
|
+
REFERENCE_FILES
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
console.log("");
|
|
98
|
+
console.log(green(" ✓ Installed in project"));
|
|
99
|
+
console.log("");
|
|
100
|
+
console.log(` ${bold(cmdCount)} commands → ${dim(commandsDest)}`);
|
|
101
|
+
console.log(` ${bold(refCount)} references → ${dim(referenceDest)}`);
|
|
102
|
+
console.log("");
|
|
103
|
+
console.log(
|
|
104
|
+
` Commands are available as ${cyan("/project:command-name")} when Claude Code runs in this directory.`
|
|
105
|
+
);
|
|
106
|
+
console.log("");
|
|
107
|
+
console.log(` ${bold("Next step:")} run:`);
|
|
108
|
+
console.log("");
|
|
109
|
+
console.log(` ${cyan("/project:magistero teach")}`);
|
|
110
|
+
console.log("");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function uninstall() {
|
|
114
|
+
let removed = 0;
|
|
115
|
+
|
|
116
|
+
const commandsDir = path.join(CLAUDE_HOME, "commands");
|
|
117
|
+
for (const file of COMMAND_FILES) {
|
|
118
|
+
const fp = path.join(commandsDir, file);
|
|
119
|
+
if (fs.existsSync(fp)) {
|
|
120
|
+
fs.unlinkSync(fp);
|
|
121
|
+
removed++;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const referenceDir = path.join(CLAUDE_HOME, "reference");
|
|
126
|
+
for (const file of REFERENCE_FILES) {
|
|
127
|
+
const fp = path.join(referenceDir, file);
|
|
128
|
+
if (fs.existsSync(fp)) {
|
|
129
|
+
fs.unlinkSync(fp);
|
|
130
|
+
removed++;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (
|
|
135
|
+
fs.existsSync(referenceDir) &&
|
|
136
|
+
fs.readdirSync(referenceDir).length === 0
|
|
137
|
+
) {
|
|
138
|
+
fs.rmdirSync(referenceDir);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
console.log("");
|
|
142
|
+
if (removed > 0) {
|
|
143
|
+
console.log(green(` ✓ Removed ${removed} files from ~/.claude/`));
|
|
144
|
+
} else {
|
|
145
|
+
console.log(dim(" Nothing to remove — skills were not installed globally."));
|
|
146
|
+
}
|
|
147
|
+
console.log("");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function printHelp() {
|
|
151
|
+
console.log("");
|
|
152
|
+
console.log(bold(" Frontend Design Skills for Claude Code"));
|
|
153
|
+
console.log("");
|
|
154
|
+
console.log(" Usage:");
|
|
155
|
+
console.log("");
|
|
156
|
+
console.log(
|
|
157
|
+
` ${cyan("npx gral-frontend-skill")} Install globally ${dim("(recommended)")}`
|
|
158
|
+
);
|
|
159
|
+
console.log(
|
|
160
|
+
` ${cyan("npx gral-frontend-skill --project")} Install in current project only`
|
|
161
|
+
);
|
|
162
|
+
console.log(
|
|
163
|
+
` ${cyan("npx gral-frontend-skill --uninstall")} Remove global installation`
|
|
164
|
+
);
|
|
165
|
+
console.log(
|
|
166
|
+
` ${cyan("npx gral-frontend-skill --help")} Show this help`
|
|
167
|
+
);
|
|
168
|
+
console.log("");
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const args = process.argv.slice(2);
|
|
172
|
+
const flag = args[0];
|
|
173
|
+
|
|
174
|
+
if (flag === "--help" || flag === "-h") {
|
|
175
|
+
printHelp();
|
|
176
|
+
} else if (flag === "--uninstall") {
|
|
177
|
+
uninstall();
|
|
178
|
+
} else if (flag === "--project") {
|
|
179
|
+
installProject();
|
|
180
|
+
} else if (!flag) {
|
|
181
|
+
installGlobal();
|
|
182
|
+
} else {
|
|
183
|
+
console.log(red(`\n Unknown flag: ${flag}\n`));
|
|
184
|
+
printHelp();
|
|
185
|
+
process.exit(1);
|
|
186
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
Identify and fix performance issues to create faster, smoother user experiences.
|
|
2
|
+
|
|
3
|
+
Target: $ARGUMENTS
|
|
4
|
+
|
|
5
|
+
## Assess Performance Issues
|
|
6
|
+
|
|
7
|
+
Understand current performance and identify problems:
|
|
8
|
+
|
|
9
|
+
1. **Measure current state**:
|
|
10
|
+
- **Core Web Vitals**: LCP, FID/INP, CLS scores
|
|
11
|
+
- **Load time**: Time to interactive, first contentful paint
|
|
12
|
+
- **Bundle size**: JavaScript, CSS, image sizes
|
|
13
|
+
- **Runtime performance**: Frame rate, memory usage, CPU usage
|
|
14
|
+
- **Network**: Request count, payload sizes, waterfall
|
|
15
|
+
|
|
16
|
+
2. **Identify bottlenecks**:
|
|
17
|
+
- What's slow? (Initial load? Interactions? Animations?)
|
|
18
|
+
- What's causing it? (Large images? Expensive JavaScript? Layout thrashing?)
|
|
19
|
+
- How bad is it? (Perceivable? Annoying? Blocking?)
|
|
20
|
+
- Who's affected? (All users? Mobile only? Slow connections?)
|
|
21
|
+
|
|
22
|
+
**CRITICAL**: Measure before and after. Premature optimization wastes time. Optimize what actually matters.
|
|
23
|
+
|
|
24
|
+
## Optimization Strategy
|
|
25
|
+
|
|
26
|
+
Create systematic improvement plan:
|
|
27
|
+
|
|
28
|
+
### Loading Performance
|
|
29
|
+
|
|
30
|
+
**Optimize Images**:
|
|
31
|
+
- Use modern formats (WebP, AVIF)
|
|
32
|
+
- Proper sizing (don't load 3000px image for 300px display)
|
|
33
|
+
- Lazy loading for below-fold images
|
|
34
|
+
- Responsive images (`srcset`, `picture` element)
|
|
35
|
+
- Compress images (80-85% quality is usually imperceptible)
|
|
36
|
+
- Use CDN for faster delivery
|
|
37
|
+
|
|
38
|
+
```html
|
|
39
|
+
<img
|
|
40
|
+
src="hero.webp"
|
|
41
|
+
srcset="hero-400.webp 400w, hero-800.webp 800w, hero-1200.webp 1200w"
|
|
42
|
+
sizes="(max-width: 400px) 400px, (max-width: 800px) 800px, 1200px"
|
|
43
|
+
loading="lazy"
|
|
44
|
+
alt="Hero image"
|
|
45
|
+
/>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Reduce JavaScript Bundle**:
|
|
49
|
+
- Code splitting (route-based, component-based)
|
|
50
|
+
- Tree shaking (remove unused code)
|
|
51
|
+
- Remove unused dependencies
|
|
52
|
+
- Lazy load non-critical code
|
|
53
|
+
- Use dynamic imports for large components
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
const HeavyChart = lazy(() => import('./HeavyChart'));
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**Optimize CSS**:
|
|
60
|
+
- Remove unused CSS
|
|
61
|
+
- Critical CSS inline, rest async
|
|
62
|
+
- Minimize CSS files
|
|
63
|
+
- Use CSS containment for independent regions
|
|
64
|
+
|
|
65
|
+
**Optimize Fonts**:
|
|
66
|
+
- Use `font-display: swap` or `optional`
|
|
67
|
+
- Subset fonts (only characters you need)
|
|
68
|
+
- Preload critical fonts
|
|
69
|
+
- Use system fonts when appropriate
|
|
70
|
+
- Limit font weights loaded
|
|
71
|
+
|
|
72
|
+
```css
|
|
73
|
+
@font-face {
|
|
74
|
+
font-family: 'CustomFont';
|
|
75
|
+
src: url('/fonts/custom.woff2') format('woff2');
|
|
76
|
+
font-display: swap;
|
|
77
|
+
unicode-range: U+0020-007F;
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**Optimize Loading Strategy**:
|
|
82
|
+
- Critical resources first (async/defer non-critical)
|
|
83
|
+
- Preload critical assets
|
|
84
|
+
- Prefetch likely next pages
|
|
85
|
+
- Service worker for offline/caching
|
|
86
|
+
- HTTP/2 or HTTP/3 for multiplexing
|
|
87
|
+
|
|
88
|
+
### Rendering Performance
|
|
89
|
+
|
|
90
|
+
**Avoid Layout Thrashing**:
|
|
91
|
+
```javascript
|
|
92
|
+
// Bad: Alternating reads and writes (causes reflows)
|
|
93
|
+
elements.forEach(el => {
|
|
94
|
+
const height = el.offsetHeight;
|
|
95
|
+
el.style.height = height * 2;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Good: Batch reads, then batch writes
|
|
99
|
+
const heights = elements.map(el => el.offsetHeight);
|
|
100
|
+
elements.forEach((el, i) => {
|
|
101
|
+
el.style.height = heights[i] * 2;
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Optimize Rendering**:
|
|
106
|
+
- Use CSS `contain` property for independent regions
|
|
107
|
+
- Minimize DOM depth (flatter is faster)
|
|
108
|
+
- Reduce DOM size (fewer elements)
|
|
109
|
+
- Use `content-visibility: auto` for long lists
|
|
110
|
+
- Virtual scrolling for very long lists (react-window, react-virtualized)
|
|
111
|
+
|
|
112
|
+
**Reduce Paint & Composite**:
|
|
113
|
+
- Use `transform` and `opacity` for animations (GPU-accelerated)
|
|
114
|
+
- Avoid animating layout properties (width, height, top, left)
|
|
115
|
+
- Use `will-change` sparingly for known expensive operations
|
|
116
|
+
- Minimize paint areas (smaller is faster)
|
|
117
|
+
|
|
118
|
+
### Animation Performance
|
|
119
|
+
|
|
120
|
+
**GPU Acceleration**:
|
|
121
|
+
```css
|
|
122
|
+
/* GPU-accelerated (fast) */
|
|
123
|
+
.animated {
|
|
124
|
+
transform: translateX(100px);
|
|
125
|
+
opacity: 0.5;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/* CPU-bound (slow) */
|
|
129
|
+
.animated {
|
|
130
|
+
left: 100px;
|
|
131
|
+
width: 300px;
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**Smooth 60fps**:
|
|
136
|
+
- Target 16ms per frame (60fps)
|
|
137
|
+
- Use `requestAnimationFrame` for JS animations
|
|
138
|
+
- Debounce/throttle scroll handlers
|
|
139
|
+
- Use CSS animations when possible
|
|
140
|
+
- Avoid long-running JavaScript during animations
|
|
141
|
+
|
|
142
|
+
**Intersection Observer**:
|
|
143
|
+
```javascript
|
|
144
|
+
const observer = new IntersectionObserver((entries) => {
|
|
145
|
+
entries.forEach(entry => {
|
|
146
|
+
if (entry.isIntersecting) {
|
|
147
|
+
// Element is visible, lazy load or animate
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### React/Framework Optimization
|
|
154
|
+
|
|
155
|
+
**React-specific**:
|
|
156
|
+
- Use `memo()` for expensive components
|
|
157
|
+
- `useMemo()` and `useCallback()` for expensive computations
|
|
158
|
+
- Virtualize long lists
|
|
159
|
+
- Code split routes
|
|
160
|
+
- Avoid inline function creation in render
|
|
161
|
+
- Use React DevTools Profiler
|
|
162
|
+
|
|
163
|
+
**Framework-agnostic**:
|
|
164
|
+
- Minimize re-renders
|
|
165
|
+
- Debounce expensive operations
|
|
166
|
+
- Memoize computed values
|
|
167
|
+
- Lazy load routes and components
|
|
168
|
+
|
|
169
|
+
### Network Optimization
|
|
170
|
+
|
|
171
|
+
**Reduce Requests**:
|
|
172
|
+
- Combine small files
|
|
173
|
+
- Use SVG sprites for icons
|
|
174
|
+
- Inline small critical assets
|
|
175
|
+
- Remove unused third-party scripts
|
|
176
|
+
|
|
177
|
+
**Optimize APIs**:
|
|
178
|
+
- Use pagination (don't load everything)
|
|
179
|
+
- GraphQL to request only needed fields
|
|
180
|
+
- Response compression (gzip, brotli)
|
|
181
|
+
- HTTP caching headers
|
|
182
|
+
- CDN for static assets
|
|
183
|
+
|
|
184
|
+
**Optimize for Slow Connections**:
|
|
185
|
+
- Adaptive loading based on connection (navigator.connection)
|
|
186
|
+
- Optimistic UI updates
|
|
187
|
+
- Request prioritization
|
|
188
|
+
- Progressive enhancement
|
|
189
|
+
|
|
190
|
+
## Core Web Vitals Optimization
|
|
191
|
+
|
|
192
|
+
### Largest Contentful Paint (LCP < 2.5s)
|
|
193
|
+
- Optimize hero images
|
|
194
|
+
- Inline critical CSS
|
|
195
|
+
- Preload key resources
|
|
196
|
+
- Use CDN
|
|
197
|
+
- Server-side rendering
|
|
198
|
+
|
|
199
|
+
### First Input Delay (FID < 100ms) / INP (< 200ms)
|
|
200
|
+
- Break up long tasks
|
|
201
|
+
- Defer non-critical JavaScript
|
|
202
|
+
- Use web workers for heavy computation
|
|
203
|
+
- Reduce JavaScript execution time
|
|
204
|
+
|
|
205
|
+
### Cumulative Layout Shift (CLS < 0.1)
|
|
206
|
+
- Set dimensions on images and videos
|
|
207
|
+
- Don't inject content above existing content
|
|
208
|
+
- Use `aspect-ratio` CSS property
|
|
209
|
+
- Reserve space for ads/embeds
|
|
210
|
+
- Avoid animations that cause layout shifts
|
|
211
|
+
|
|
212
|
+
```css
|
|
213
|
+
.image-container {
|
|
214
|
+
aspect-ratio: 16 / 9;
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Performance Monitoring
|
|
219
|
+
|
|
220
|
+
**Tools to use**:
|
|
221
|
+
- Chrome DevTools (Lighthouse, Performance panel)
|
|
222
|
+
- WebPageTest
|
|
223
|
+
- Core Web Vitals (Chrome UX Report)
|
|
224
|
+
- Bundle analyzers (webpack-bundle-analyzer)
|
|
225
|
+
- Performance monitoring (Sentry, DataDog, New Relic)
|
|
226
|
+
|
|
227
|
+
**Key metrics**:
|
|
228
|
+
- LCP, FID/INP, CLS (Core Web Vitals)
|
|
229
|
+
- Time to Interactive (TTI)
|
|
230
|
+
- First Contentful Paint (FCP)
|
|
231
|
+
- Total Blocking Time (TBT)
|
|
232
|
+
- Bundle size
|
|
233
|
+
- Request count
|
|
234
|
+
|
|
235
|
+
**IMPORTANT**: Measure on real devices with real network conditions. Desktop Chrome with fast connection isn't representative.
|
|
236
|
+
|
|
237
|
+
**NEVER**:
|
|
238
|
+
- Optimize without measuring (premature optimization)
|
|
239
|
+
- Sacrifice accessibility for performance
|
|
240
|
+
- Break functionality while optimizing
|
|
241
|
+
- Use `will-change` everywhere (creates new layers, uses memory)
|
|
242
|
+
- Lazy load above-fold content
|
|
243
|
+
- Optimize micro-optimizations while ignoring major issues (optimize the biggest bottleneck first)
|
|
244
|
+
- Forget about mobile performance (often slower devices, slower connections)
|
|
245
|
+
|
|
246
|
+
## Verify Improvements
|
|
247
|
+
|
|
248
|
+
Test that optimizations worked:
|
|
249
|
+
|
|
250
|
+
- **Before/after metrics**: Compare Lighthouse scores
|
|
251
|
+
- **Real user monitoring**: Track improvements for real users
|
|
252
|
+
- **Different devices**: Test on low-end Android, not just flagship iPhone
|
|
253
|
+
- **Slow connections**: Throttle to 3G, test experience
|
|
254
|
+
- **No regressions**: Ensure functionality still works
|
|
255
|
+
- **User perception**: Does it *feel* faster?
|
|
256
|
+
|
|
257
|
+
Remember: Performance is a feature. Fast experiences feel more responsive, more polished, more professional. Optimize systematically, measure ruthlessly, and prioritize user-perceived performance.
|