angular-performance by gentleman-programming/gentleman-skills
npx skills add https://github.com/gentleman-programming/gentleman-skills --skill angular-performanceimport { NgOptimizedImage } from '@angular/common';
@Component({
imports: [NgOptimizedImage],
template: `
<!-- LCP 图像:添加 priority 属性 -->
<img ngSrc="hero.jpg" width="800" height="400" priority>
<!-- 常规图像:默认延迟加载 -->
<img ngSrc="thumb.jpg" width="200" height="200">
<!-- 填充模式(父元素需要 position: relative) -->
<img ngSrc="bg.jpg" fill>
<!-- 带占位符 -->
<img ngSrc="photo.jpg" width="400" height="300" placeholder>
`
})
width 和 height(或使用 fill)priority 属性ngSrc,而非 广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
srcfill 模式图像的父元素必须具有 position: relative/fixed/absolute@defer (on viewport) {
<heavy-component />
} @placeholder {
<p>立即显示的占位符</p>
} @loading (minimum 200ms) {
<spinner />
} @error {
<p>加载失败</p>
}
| 触发器 | 使用场景 |
|---|---|
on viewport | 首屏以下的内容 |
on interaction | 点击/聚焦/悬停时加载 |
on idle | 浏览器空闲时加载 |
on timer(500ms) | 延迟指定时间后加载 |
when condition | 当表达式为真时加载 |
<!-- 多个触发器 -->
@defer (on viewport; on interaction) {
<comments />
}
<!-- 条件触发 -->
@defer (when showComments()) {
<comments />
}
// 单个组件
{
path: 'admin',
loadComponent: () => import('./features/admin/admin').then(c => c.AdminComponent)
}
// 包含子路由的功能模块
{
path: 'users',
loadChildren: () => import('./features/users/routes').then(m => m.USERS_ROUTES)
}
bootstrapApplication(AppComponent, {
providers: [
provideClientHydration()
]
});
| 场景 | 使用 |
|---|---|
| SEO 关键页面(博客、电商) | SSR |
| 仪表盘/管理后台 | CSR |
| 静态营销网站 | SSG/预渲染 |
| 解决方案 | 适用场景 |
|---|---|
| 优化算法 | 始终首选 |
| 纯管道 | 缓存单个结果 |
| 记忆化 | 缓存多个结果 |
computed() | 派生信号状态 |
切勿在生命周期钩子(ngOnInit、ngAfterViewInit)中触发重排/重绘。
每周安装量
137
代码仓库
GitHub 星标数
362
首次出现
2026年1月24日
安全审计
安装于
opencode123
codex112
gemini-cli112
github-copilot107
kimi-cli103
amp101
import { NgOptimizedImage } from '@angular/common';
@Component({
imports: [NgOptimizedImage],
template: `
<!-- LCP image: add priority -->
<img ngSrc="hero.jpg" width="800" height="400" priority>
<!-- Regular: lazy loaded by default -->
<img ngSrc="thumb.jpg" width="200" height="200">
<!-- Fill mode (parent needs position: relative) -->
<img ngSrc="bg.jpg" fill>
<!-- With placeholder -->
<img ngSrc="photo.jpg" width="400" height="300" placeholder>
`
})
width and height (or fill)priority to LCP (Largest Contentful Paint) imagengSrc not srcfill image must have position: relative/fixed/absolute@defer (on viewport) {
<heavy-component />
} @placeholder {
<p>Placeholder shown immediately</p>
} @loading (minimum 200ms) {
<spinner />
} @error {
<p>Failed to load</p>
}
| Trigger | When to Use |
|---|---|
on viewport | Below the fold content |
on interaction | Load on click/focus/hover |
on idle | Load when browser is idle |
on timer(500ms) | Load after delay |
when condition | Load when expression is true |
<!-- Multiple triggers -->
@defer (on viewport; on interaction) {
<comments />
}
<!-- Conditional -->
@defer (when showComments()) {
<comments />
}
// Single component
{
path: 'admin',
loadComponent: () => import('./features/admin/admin').then(c => c.AdminComponent)
}
// Feature with child routes
{
path: 'users',
loadChildren: () => import('./features/users/routes').then(m => m.USERS_ROUTES)
}
bootstrapApplication(AppComponent, {
providers: [
provideClientHydration()
]
});
| Scenario | Use |
|---|---|
| SEO critical (blog, e-commerce) | SSR |
| Dashboard/Admin | CSR |
| Static marketing site | SSG/Prerender |
| Solution | When |
|---|---|
| Optimize algorithm | First choice always |
| Pure pipes | Cache single result |
| Memoization | Cache multiple results |
computed() | Derived signal state |
NEVER trigger reflows/repaints in lifecycle hooks (ngOnInit, ngAfterViewInit).
Weekly Installs
137
Repository
GitHub Stars
362
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode123
codex112
gemini-cli112
github-copilot107
kimi-cli103
amp101
TanStack Query v5 完全指南:React 数据管理、乐观更新、离线支持
2,500 周安装
合规审计专家:SOC2、HIPAA、GDPR、PCI DSS 合规审计、差距分析与整改指导
141 周安装
agent-browser 浏览器自动化工具 - 快速网页交互与测试命令行工具
134 周安装
游戏安全逆向工程工具大全:调试、反编译、内存分析与反作弊绕过
135 周安装
Flutter 表单验证教程:使用 Form、TextFormField 和 GlobalKey 实现高效验证
135 周安装
Apache ECharts 教程 - 20+交互式图表制作与数据可视化技能
136 周安装
UI/UX设计参考数据库 - 可搜索模式、样式、调色板、字体搭配与技术栈指南
136 周安装