Skip to content

craigharman/htmx-ext-no-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

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.

About

Bypass caching for selected HTMX requests.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •