htmx-ext-no-cache

1.0.2 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i htmx-ext-no-cache

Weekly Downloads

7

Version

1.0.2

License

ISC

Unpacked Size

1.88 kB

Total Files

3

Last publish

Collaborators

  • craigharman