# instajax

> Instantly move your multi page application navigations to AJAX

Latest version **2.1.0** (published 2026-11-19) · AGPL-3.0-only license · 0 weekly downloads

## Install

```sh
npm install instajax
pnpm add instajax
yarn add instajax
bun add instajax
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2026-11-19 |
| First published | 2024-11-06 |
| Weekly downloads | 0 |
| License | AGPL-3.0-only |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Ufuk Bakan |
| Maintainers | ufukbakan |
| Keywords | js, ajax, navigation, route, history, spa, single page application, faster, performance, instant, fast, load, quick, web development, javascript, node.js, browser, html, php, navigate, mpa, multi-page application, router, routing, url, location, window, history API, pushState, replaceState, popstate, xml, http request, xmlhttprequest, fetch |

## Links

- npm: https://www.npmjs.com/package/instajax
- Repository: https://github.com/instant-docs/instajax
- Homepage: https://github.com/instant-docs/instajax#readme
- Issues: https://github.com/instant-docs/instajax/issues
- npm.io page: https://npm.io/package/instajax

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.1.0 (latest) — 2026-11-19
- 2.0.1 — 2025-09-24
- 2.0.0 — 2025-07-10
- 1.7.1 — 2025-05-30
- 1.7.0 — 2025-05-30
- 1.6.1 — 2024-11-07
- 1.6.0 — 2024-11-07
- 1.5.1 — 2024-11-07
- 1.5.0 — 2024-11-07
- 1.4.0 — 2024-11-07
- 1.3.0 — 2024-11-07
- 1.2.0 — 2024-11-07
- 1.0.0 — 2024-11-07
- 0.0.4 — 2024-11-06
- 0.0.3 — 2024-11-06
- … 1 more at https://npm.io/package/instajax/versions

## README

# 🚀 Instajax

Instajax is a lightweight JavaScript library that enhances web app navigation by seamlessly updating 
content via AJAX without reloading the page. It leverages modern browser features like `fetch`, 
`history.pushState`, and `MutationObserver` to provide a smooth user experience.

## 📋 Features
- ⚡ **Lightweight**: Extremely lightweight, perfect for performance-conscious applications.
- 🌍 **Seamless Navigation**: Updates content without reloading the page using AJAX.
- 🖥️ **Modern Browser Support**: Utilizes cutting-edge browser APIs (`fetch`, `history.pushState`, and 
`MutationObserver`).
- 🎨 **Customization Options**: Easily customize error templates with HTML strings or URLs to external 
files.
- 🛠️ **Easy Integration**: Seamlessly integrates into projects via CDN, npm, or yarn for easy adoption.

## 🛠️ Usage
### CDN Method
Put the script tag to head of your template HTML. It will initialize automatically.
```html
<script type="module" src="https://unpkg.com/instajax@1.7.1/dist/min.js"></script>
```

### Package Manager Method
You can install it via npm or yarn and import it in your project:
```bash
npm install instajax
```
Then in your main client-side JavaScript code, just import it:
```javascript
import 'instajax';
```

Within your HTML, Instajax will handle links automatically without reloading the page:
```html
<a href="/new-page">Go to new page via instajax</a>
<a href="/new-page" class="skip-instajax">Go to new page without instajax</a>
```

## 📜 Scroll Behavior
By default, Instajax scrolls to the top of the page after a navigation. To keep the current scroll
position, opt in explicitly with the `data-preserve-scroll` attribute:

```html
<a href="/new-page" data-preserve-scroll>Keep my scroll position</a>
```

For browser back/forward navigation, put the attribute on the page's `<body>` element:

```html
<body data-preserve-scroll>
```

## 🎨 Customization
To customize the error template, you can call the default function with a custom HTML string or URL 
pointing to an HTML file:
```javascript
import instajax from 'instajax';
instajax({ errorHTML: '<div class="error">%error%</div>' });
```
or
```javascript
instajax({ errorHTML: 'url("/error.html")' });
```

## 📡 API Functions
- **default({ errorHTML })**
  
  Customizes the default error template with a provided HTML string or URL pointing to an HTML file.

---
_Source: https://npm.io/package/instajax · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
