> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Main-Thread Scripts

Touch handlers that restyle an element on every event, with no Angular re-render in between. Look here before you build drag- or scroll-driven effects.


## What it shows

- **`mainThreadFn()`** — wraps a handler as a **main-thread script** ([Glossary](/guide/glossary.md#main-thread-script)) that edits the element directly with `setStyleProperty()`. See [`mainThreadFn`](/api/main-thread/main-thread-fn.md).
- **`[mainThreadBindtap]` and `[mainThreadBindtouchmove]`** — bind those handlers to an element's events. Import `LynxMainThreadEvent` to use them. See [`LynxMainThreadEvent`](/api/main-thread/main-thread-event.md).
- **`createMainThreadRef()`** — keeps the tap count between calls. See [`MainThreadRef`](/api/main-thread/main-thread-ref.md).
- **`backgroundFn()` and `runOnBackground()`** — call a function on the **background thread** ([Glossary](/guide/glossary.md#background-thread)) from a main-thread script. See [`backgroundFn`](/api/main-thread/background-fn.md).
- **A plain `(bindtap)` for comparison** — the third box updates a signal and lets Angular re-render. Use that for most handlers.

## Related

- [Main-thread scripts](/guide/main-thread/index.md)
- [Threads: where your code runs](/guide/concepts/threads.md)
