javascript-async-dom
2
总安装量
2
周安装量
#68762
全站排名
安装命令
npx skills add https://github.com/sraloff/gravityboots --skill javascript-async-dom
Agent 安装分布
opencode
2
gemini-cli
2
claude-code
2
github-copilot
2
codex
2
kimi-cli
2
Skill 文档
JavaScript Async & DOM
When to use this skill
- Manipulating usage of
fetchorXMLHttpRequest. - Adding event listeners to DOM elements.
- Interacting with browser APIs (Local Storage, Navigator).
1. Async Data Fetching
- Fetch API: Use
fetch()with async/await. Always checkres.okbefore parsing JSON.const res = await fetch('/api/data'); if (!res.ok) throw new Error('Failed'); const data = await res.json(); - AbortController: Use
AbortControllerto cancel pending requests when components unmount or fast interactions occur.
2. event Delegation
- Listener Attachment: Attach listeners to a parent container rather than individual items for lists.
list.addEventListener('click', (e) => { if (e.target.matches('.item-btn')) { ... } }); - Cleanup: Always use
removeEventListenerif listeners are attached to transient elements (or use{ once: true }where applicable).
3. DOM Manipulation
- Performance: Minimize reflows. Read layout properties (offsetWidth, etc.) in a batch, then write styles in a batch.
- Fragments: Use
DocumentFragmentwhen appending multiple elements to the DOM at once.