htmx-ext-no-cache
v1.0.2
Published
Bypass caching for a specific HTMX request
Downloads
17
Readme
No cache HTMX Extension
Will force an HTMX request to break cache and get a new request. Works automatically on client-side and provides a hx-no-cache
header for implementation on the server.
Usage
Script tag
HTMX recommends you link from unpkg:
<head>
...
<script src="https://unpkg.com/htmx-ext-no-cache@^1/no-load.js" defer></script>
...
</head>
NPM package
If you are using Vite as a package manager.
npm install @rollup/plugin-inject htmx-ext-no-cache
// vite.config.js
import inject from '@rollup/plugin-inject'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [
inject({
htmx: 'htmx.org'
}),
],
})
// app.js
import 'htmx-ext-no-cache'
import htmx from 'htmx.org'
In your HTML:
<body>
<button hx-get="/your-endpoint" hx-ext="no-cache">Click me</button>
</body>
Add the hx-ext="no-cache"
to any HTMX element you don't want to cache.