javascript-inline
它能做什么
这个技能检查页面中直接写在 HTML 里的 JavaScript,例如 onclick 属性。它面向希望代码更清晰、安全性更强的开发者。
适用场景
- ✓你的 HTML 中有 onclick 或 onmouseover 属性的时候。
- ✓你的网站有内容安全策略,会阻止内联脚本的时候。
- ✓你希望脚本能被缓存并在多个页面间复用的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/javascript-inline/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我把页面 HTML 中的内联 JavaScript 移到单独的文件里吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会找出内联事件处理程序和脚本代码块,并建议用 addEventListener 把它们移到外部文件里。在确有必要时,它只保留关键的首屏代码为内联。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Avoid inline JavaScript
Inline JavaScript breaks browser caching, violates Content Security Policy (CSP), and creates unmaintainable spaghetti code mixing markup with behavior.
Quick Reference
- Move onclick/onmouseover handlers to external JS files
- Use addEventListener instead of inline event handlers
- Exception: critical above-the-fold JS can be inlined
- External files enable browser caching across pages
Check
Verify that JavaScript code is not mixed with HTML markup using external script files and proper separation of concerns for better maintainability and performance.
Fix
Move inline JavaScript to external files, implement proper event handling, and use modern JavaScript patterns for DOM interaction.
Explain
Explain why separating JavaScript from HTML improves maintainability, enables caching, reduces security risks, and follows best practices for separation of concerns.
Code Review
Review scripts, client components, and browser execution paths related to Avoid inline JavaScript. Flag exact imports, event handlers, runtime side effects, or blocking operations that violate the rule, and state how the change should be verified in the browser.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/javascript/javascript-inline
常见问题
为什么内联 JavaScript 是个问题?
这个技能说,它无法被单独缓存,可能与内容安全策略冲突,还会把标记和行为混在一起。
onclick 应该用什么替代?
这个技能建议在外部脚本文件中使用 addEventListener。
有没有哪些内联 JavaScript 是可以接受的?
这个技能说,关键的首屏 JavaScript 可以作为例外保留为内联。
详情
作者的原始描述
Use when reviewing scripts, client components, bundles, or runtime behavior related to Avoid inline JavaScript. Inspect both source code and the browser execution path so fixes target the real bottleneck or bug.
热度
- GitHub 星标
- 75k
- 排名
- #2900
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。