跳到正文
Skillpedia
网站与界面(前端)75k · #2900

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/javascript-inline/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#2900
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能