prefetch — скилл для Claude Code: что делает и как установить
Скилл объясняет агенту техники предзагрузки ресурсов в браузере во время простоя. Помогает ускорить открытие следующих страниц и тяжёлых модальных окон.
npx skills add PatternsDev/skills --skill prefetch -a claude-codeЧто делает prefetch
Скилл учит агента использовать <link rel="prefetch">, HTTP-заголовок Link и комментарии сборщика Webpack вроде /* webpackPrefetch: true */. Браузер запрашивает такие модули с низким приоритетом, когда сеть свободна. В итоге к моменту клика пользователя нужный бандл уже лежит в кэше.
Инструкции ориентированы на файлы **/*.js и **/*.ts. Скилл прямо предостерегает от слепой предзагрузки всего подряд: лишние запросы тратят мобильный трафик пользователя и создают ненужную конкуренцию за канал. Если данные часто меняются, они попросту устареют в кэше до клика.
Никаких внешних сервисов или API-ключей для работы не требуется. Это свод правил по архитектуре клиентского кода, рассчитанный на веб-проекты со сборщиками модулей или статической HTML-разметкой.
Какие задачи решает
- настроить предзагрузку отложенных JS-чанков через Webpack
- ускорить открытие тяжёлых компонентов и диалоговых окон
- добавить теги
<link rel="prefetch">для вероятных следующих страниц - исключить лишнюю нагрузку на сеть при нестабильном соединении
Примеры запросов агенту
- Настрой предзагрузку чанка EmojiPicker через комментарии Webpack
- Добавь prefetch для следующей страницы каталога в HTML-разметку
- Проверь код и подскажи, стоит ли предзагружать этот модуль
Как установить prefetch
1Через Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill prefetch -a claude-code2Вручную: положить файлы
~/.claude/skills/prefetch/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/prefetch/
1Через Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill prefetch -a codex2Вручную: положить файлы
.agents/skills/prefetch/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill prefetch -a cursor2Вручную: положить файлы
.cursor/skills/prefetch/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install PatternsDev/skills prefetch2Вручную: положить файлы
.github/skills/prefetch/SKILL.md1Через Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill prefetch -a gemini-cli2Командой платформы
gemini skills install https://github.com/PatternsDev/skills --path javascript/prefetchВручную: положить файлы
.devin/skills/prefetch/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Через Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill prefetch -a opencodeClaude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов
Вопросы о prefetch
Как установить prefetch в Claude Code?
Выполните в терминале команду npx skills add PatternsDev/skills --skill prefetch -a claude-code. Агент получит доступ к инструкциям по префетчингу.
Что делает скилл prefetch?
Он объясняет ассистенту правила фоновой предзагрузки ресурсов в браузере. Агент помогает настроить импорты в Webpack или теги в HTML, чтобы файлы загружались заранее в моменты простоя.
Когда не стоит применять предзагрузку?
Нельзя префетчить данные, которые быстро устаревают, а также ресурсы с низкой вероятностью просмотра. На медленных или тарифицируемых соединениях фоновая загрузка только тратит трафик пользователя.
Исходный текст
SKILL.md · MIT
---
name: prefetch
description: Teaches resource prefetching strategies for faster navigation. Use when you can predict which resources the user will need next and want to load them during idle time.
paths:
- "**/*.js"
- "**/*.ts"
license: MIT
metadata:
author: patterns.dev
version: "1.1"
related_skills:
- "module-pattern"
- "singleton-pattern"
---
# Prefetch
Prefetch (`<link rel="prefetch">`) is a browser optimization which allows us to fetch resources that may be needed for subsequent routes or pages before they are needed. Prefetching can be achieved in a few ways. It can be done declaratively in HTML (such as in the example below), via a HTTP Header (`Link: </js/chat-widget.js>; rel=prefetch`), [Service Workers](https://googlechrome.github.io/samples/service-worker/prefetch/) or via more custom means such as through Webpack.
## When to Use
- Use this when you know users will likely navigate to certain routes or need certain resources soon
- This is helpful for reducing perceived loading time on subsequent navigations
## When NOT to Use
- For resources unlikely to be needed — unnecessary prefetching wastes bandwidth and competes with critical requests
- On low-bandwidth or metered connections where prefetching consumes the user's data budget
- When the prefetched resources change frequently and would be stale by the time they're used
## Instructions
- Use `<link rel="prefetch">` or Webpack magic comments (`/* webpackPrefetch: true */`) to prefetch resources
- Only prefetch resources that are likely to be needed — don't overdo it as it consumes bandwidth
- Prefetched resources are loaded at low priority when the browser is idle
## Details
```html
<link rel="prefetch" href="/pages/next-page.html" />
<link rel="prefetch" href="/js/emoji-picker.js" />
```
### Prefetch
In the examples showing how we can import modules based on visibility or interaction, we saw that there was often some delay between clicking on the button in order to toggle the component, and showing the actual component on the screen. This happened, since the module still had to get requested and loaded when the user clicked on the button!
In many cases, we know that users will request certain resources soon after the initial render of a page. Although they may not visible instantly, thus shouldn't be included in the initial bundle, it would be great to reduce the loading time as much as possible to give a better user experience!
Components or resources that we know are likely to be used at some point in the application can be **prefetched**. We can let Webpack know that certain bundles need to be prefetched, by adding a [magic comment](https://webpack.js.org/api/module-methods/#magic-comments) to the import statement: `/* webpackPrefetch: true */`.
```js
const EmojiPicker = import(/* webpackPrefetch: true */ "./EmojiPicker");
```
After building the application, we can see that the `EmojiPicker` will be prefetched.
```
Asset Size Chunks Chunk Names
emoji-picker.bundle.js 1.49 KiB emoji-picker [emitted] emoji-picker
vendors~emoji-picker.bundle.js 171 KiB vendors~emoji-picker [emitted] vendors~emoji-picker
main.bundle.js 1.34 MiB main [emitted] main
Entrypoint main = main.bundle.js
(prefetch: vendors~emoji-picker.bundle.js emoji-picker.bundle.js)
```
The actual output is visible as a `link` tag with `rel="prefetch"` in the `head` of our document.
```html
<link rel="prefetch" href="emoji-picker.bundle.js" as="script" />
<link rel="prefetch" href="vendors~emoji-picker.bundle.js" as="script" />
```
Modules that are prefetched are requested and loaded by the browser even **before the user requested the resource**. When the browser is idle and calculates that it's got enough bandwidth, it will make a request in order to load the resource, and cache it. Having the resource cached can reduce the loading time significantly, as we don't have to wait for the request to finish after the user has clicked the button. It can simply get the loaded resource from cache.
Although prefetching is a great way to optimize the loading time, don't overdo it. If the user ended up never requesting the `EmojiPicker` component, we unnecessarily loaded the resource. This could potentially cost a user money, or slow down the application. Only prefetch the necessary resources.
## Source
- [patterns.dev/vanilla/prefetch](https://patterns.dev/vanilla/prefetch)
### References
- [Preload, prefetch and priorities in Chrome](https://medium.com/reloading/preload-prefetch-and-priorities-in-chrome-776165961bbf)
- [Faster navigations with predictive prefetching](https://web.dev/predictive-prefetching/)
- [Prefetching heuristics](https://blog.mgechev.com/2021/02/07/prefetching-strategies-heuristics-faster-web-apps/)
- [What not to prefetch](https://addyosmani.com/blog/what-not-to-prefetch-prerender/)
© patterns.dev · MIT · PatternsDev/skills