You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extension docs: npm, bundler, min/unmin and SRI hash instructions (#3127)
* Extensions docs: add npm/bundler installation guide and up versions numbers for links
* Revert extensions._index.md table change
* Update docs.md extension installation and integration instruction
* Move extension installation and enabling to new sections in docs.md
* Update extension installation guidelines
* Update idiomorph installation guidelines
* Minor consistency edits
* Make the need for hx-ext clearer
* Fix typos and note for community repos not hosted outside this repo
*[idiomorph](/extensions/idiomorph) - supports the `morph` swap strategy using idiomorph
1149
1130
*[preload](/extensions/preload) - allows you to preload content for better performance
@@ -1153,6 +1134,56 @@ htmx supports a few "core" extensions, which are supported by the htmx developme
1153
1134
1154
1135
You can see all available extensions on the [Extensions](/extensions) page.
1155
1136
1137
+
### Installing Extensions
1138
+
1139
+
The fastest way to install htmx extensions created by others is to load them via a CDN. Remember to always include the core htmx library before the extensions and [enable the extension](#enabling-extensions). For example, if you would like to use the [response-targets](/extensions/response-targets) extension, you can add this to your head tag:
An unminified version is also available at `https://unpkg.com/htmx-ext-extension-name/dist/extension-name.js` (replace `extension-name` with the name of the extension).
1149
+
1150
+
While the CDN approach is simple, you may want to consider [not using CDNs in production](https://blog.wesleyac.com/posts/why-not-javascript-cdn). The next easiest way to install htmx extensions is to simply copy them into your project. Download the extension from `https://unpkg.com/htmx-ext-extension-name` (replace `extension-name` with the name of the extension) e.g., https://unpkg.com/htmx-ext-response-targets. Then add it to the appropriate directory in your project and include it where necessary with a `<script>` tag.
1151
+
1152
+
For npm-style build systems, you can install htmx extensions via [npm](https://www.npmjs.com/) (replace `extension-name` with the name of the extension):
1153
+
```shell
1154
+
npm install htmx-ext-extension-name
1155
+
```
1156
+
After installing, you'll need to use appropriate tooling to bundle `node_modules/htmx-ext-extension-name/dist/extension-name.js` (or `.min.js`). For example, you might bundle the extension with htmx core from `node_modules/htmx.org/dist/htmx.js` and project-specific code.
1157
+
1158
+
If you are using a bundler to manage your javascript (e.g. Webpack, Rollup):
1159
+
- Install `htmx.org` and `htmx-ext-extension-name` via npm (replace `extension-name` with the name of the extension)
1160
+
- Import both packages to your `index.js`
1161
+
```JS
1162
+
import`htmx.org`;
1163
+
import`htmx-ext-extension-name`; // replace `extension-name` with the name of the extension
1164
+
```
1165
+
1166
+
Note: [Idiomorph](/extensions/idiomorph) does not follow the naming convention of htmx extensions. Use `idiomorph` instead of `htmx-ext-idiomorph`. For example, `https://unpkg.com/idiomorph` or `npm install idiomorph`.
1167
+
1168
+
Note: Community extensions hosted outside this repository might have different installation instructions. Please check the corresponding repository for set-up guidance.
1169
+
1170
+
### Enabling Extensions
1171
+
1172
+
To enable an extension, add a `hx-ext="extension-name"` attribute to `<body>` or another HTML element (replace `extension-name` with the name of the extension). The extension will be applied to all child elements.
1173
+
1174
+
The following example shows how to enable [response-targets](/extensions/response-targets) extension, allowing you to specify different target elements to be swapped based on HTTP response code.
The fastest way to install `head-support` is to load it via a CDN. Remember to always include the core htmx library before the extension and [enable the extension](#usage).
An unminified version is also available at https://unpkg.com/htmx-ext-head-support/dist/head-support.js.
28
+
29
+
While the CDN approach is simple, you may want to consider [not using CDNs in production](https://blog.wesleyac.com/posts/why-not-javascript-cdn). The next easiest way to install `head-support` is to simply copy it into your project. Download the extension from `https://unpkg.com/htmx-ext-head-support`, add it to the appropriate directory in your project and include it where necessary with a `<script>` tag.
30
+
31
+
For npm-style build systems, you can install `head-support` via [npm](https://www.npmjs.com/):
32
+
```shell
33
+
npm install htmx-ext-head-support
34
+
```
35
+
After installing, you'll need to use appropriate tooling to bundle `node_modules/htmx-ext-head-support/dist/head-support.js` (or `.min.js`). For example, you might bundle the extension with htmx core from `node_modules/htmx.org/dist/htmx.js` and project-specific code.
36
+
37
+
If you are using a bundler to manage your javascript (e.g. Webpack, Rollup):
38
+
- Install `htmx.org` and `htmx-ext-head-support` via npm
Copy file name to clipboardExpand all lines: www/content/extensions/htmx-1-compat.md
+25-3Lines changed: 25 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,33 @@ title = "htmx 1.x Compatibility Extension"
4
4
5
5
The `htmx-1-compat` extension allows you to almost seamlessly upgrade from htmx 1.x to htmx 2.
6
6
7
-
## Install
7
+
## Installing
8
+
9
+
The fastest way to install `htmx-1-compat` is to load it via a CDN. Remember to always include the core htmx library before the extension and enable the extension.
An unminified version is also available at https://unpkg.com/htmx-ext-htmx-1-compat/dist/htmx-1-compat.js.
8
19
9
-
```html
20
+
While the CDN approach is simple, you may want to consider [not using CDNs in production](https://blog.wesleyac.com/posts/why-not-javascript-cdn). The next easiest way to install `htmx-1-compat` is to simply copy it into your project. Download the extension from `https://unpkg.com/htmx-ext-htmx-1-compat`, add it to the appropriate directory in your project and include it where necessary with a `<script>` tag.
For npm-style build systems, you can install `htmx-1-compat` via [npm](https://www.npmjs.com/):
23
+
```shell
24
+
npm install htmx-ext-htmx-1-compat
25
+
```
26
+
After installing, you'll need to use appropriate tooling to bundle `node_modules/htmx-ext-htmx-1-compat/dist/htmx-1-compat.js` (or `.min.js`). For example, you might bundle the extension with htmx core from `node_modules/htmx.org/dist/htmx.js` and project-specific code.
27
+
28
+
If you are using a bundler to manage your javascript (e.g. Webpack, Rollup):
29
+
- Install `htmx.org` and `htmx-ext-htmx-1-compat` via npm
The fastest way to install `idiomorph` is to load it via a CDN. Remember to always include the core htmx library before the extension and [enable the extension](#usage).
An unminified version is also available at https://unpkg.com/idiomorph/dist/idiomorph.js.
24
+
25
+
While the CDN approach is simple, you may want to consider [not using CDNs in production](https://blog.wesleyac.com/posts/why-not-javascript-cdn). The next easiest way to install `idiomorph` is to simply copy it into your project. Download the extension from `https://unpkg.com/idiomorph`, add it to the appropriate directory in your project and include it where necessary with a `<script>` tag.
26
+
27
+
For npm-style build systems, you can install `idiomorph` via [npm](https://www.npmjs.com/):
28
+
```shell
29
+
npm install idiomorph
30
+
```
31
+
After installing, you'll need to use appropriate tooling to bundle `node_modules/idiomorph/dist/idiomorph.js` (or `.min.js`). For example, you might bundle the extension with htmx core from `node_modules/htmx.org/dist/htmx.js` and project-specific code.
32
+
33
+
If you are using a bundler to manage your javascript (e.g. Webpack, Rollup):
Copy file name to clipboardExpand all lines: www/content/extensions/preload.md
+26-4Lines changed: 26 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,10 +10,33 @@ behavior to fit your applications needs and use cases.
10
10
too many resources can negatively impact your visitors' bandwidth and your server performance by initiating too many
11
11
unused requests. Use this extension carefully!
12
12
13
-
## Install
13
+
## Installing
14
+
15
+
The fastest way to install `preload` is to load it via a CDN. Remember to always include the core htmx library before the extension and [enable the extension](#usage).
While the CDN approach is simple, you may want to consider [not using CDNs in production](https://blog.wesleyac.com/posts/why-not-javascript-cdn). The next easiest way to install `preload` is to simply copy it into your project. Download the extension from `https://unpkg.com/htmx-ext-preload`, add it to the appropriate directory in your project and include it where necessary with a `<script>` tag.
27
+
28
+
For npm-style build systems, you can install `preload` via [npm](https://www.npmjs.com/):
29
+
```shell
30
+
npm install htmx-ext-preload
31
+
```
32
+
After installing, you'll need to use appropriate tooling to bundle `node_modules/htmx-ext-preload/dist/preload.js` (or `.min.js`). For example, you might bundle the extension with htmx core from `node_modules/htmx.org/dist/htmx.js` and project-specific code.
33
+
34
+
If you are using a bundler to manage your javascript (e.g. Webpack, Rollup):
35
+
- Install `htmx.org` and `htmx-ext-preload` via npm
36
+
- Import both packages to your `index.js`
37
+
```JS
38
+
import`htmx.org`;
39
+
import`htmx-ext-preload`;
17
40
```
18
41
19
42
## Usage
@@ -23,7 +46,6 @@ and `hx-get` elements you want to preload. By default, resources will be loaded
23
46
giving your application a roughly 100-200ms head start on serving responses. See configuration below for other options.
24
47
25
48
```html
26
-
27
49
<bodyhx-ext="preload">
28
50
<h1>What Works</h2>
29
51
<ahref="/server/1"preload>WILL BE requested using a standard XMLHttpRequest() and default options (below)</a>
Copy file name to clipboardExpand all lines: www/content/extensions/response-targets.md
+26-3Lines changed: 26 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,10 +22,33 @@ The value of each attribute can be:
22
22
*`previous <CSS selector>` which will scan the DOM backwards for the first element that matches the given CSS selector.
23
23
(e.g `previous .error` will target the closest previous sibling with `error` class)
24
24
25
-
## Install
25
+
## Installing
26
+
27
+
The fastest way to install `response-targets` is to load it via a CDN. Remember to always include the core htmx library before the extension and [enable the extension](#usage).
While the CDN approach is simple, you may want to consider [not using CDNs in production](https://blog.wesleyac.com/posts/why-not-javascript-cdn). The next easiest way to install `response-targets` is to simply copy it into your project. Download the extension from `https://unpkg.com/htmx-ext-response-targets`, add it to the appropriate directory in your project and include it where necessary with a `<script>` tag.
39
+
40
+
For npm-style build systems, you can install `response-targets` via [npm](https://www.npmjs.com/):
41
+
```shell
42
+
npm install htmx-ext-response-targets
43
+
```
44
+
After installing, you'll need to use appropriate tooling to bundle `node_modules/htmx-ext-response-targets/dist/response-targets.js` (or `.min.js`). For example, you might bundle the extension with htmx core from `node_modules/htmx.org/dist/htmx.js` and project-specific code.
45
+
46
+
If you are using a bundler to manage your javascript (e.g. Webpack, Rollup):
47
+
- Install `htmx.org` and `htmx-ext-response-targets` via npm
Copy file name to clipboardExpand all lines: www/content/extensions/sse.md
+24-3Lines changed: 24 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,11 +24,32 @@ Use the following attributes to configure how SSE connections behave:
24
24
*`sse-close=<message-name>` - To close the EventStream gracefully when that message is received. This might be helpful
25
25
if you want to send information to a client that will eventually stop.
26
26
27
-
## Install
27
+
## Installing
28
+
29
+
The fastest way to install `sse` is to load it via a CDN. Remember to always include the core htmx library before the extension and [enable the extension](#usage).
An unminified version is also available at https://unpkg.com/htmx-ext-sse/dist/sse.js.
28
38
29
-
```html
39
+
While the CDN approach is simple, you may want to consider [not using CDNs in production](https://blog.wesleyac.com/posts/why-not-javascript-cdn). The next easiest way to install `sse` is to simply copy it into your project. Download the extension from `https://unpkg.com/htmx-ext-sse`, add it to the appropriate directory in your project and include it where necessary with a `<script>` tag.
For npm-style build systems, you can install `sse` via [npm](https://www.npmjs.com/):
42
+
```shell
43
+
npm install htmx-ext-sse
44
+
```
45
+
After installing, you'll need to use appropriate tooling to bundle `node_modules/htmx-ext-sse/dist/sse.js` (or `.min.js`). For example, you might bundle the extension with htmx core from `node_modules/htmx.org/dist/htmx.js` and project-specific code.
46
+
47
+
If you are using a bundler to manage your javascript (e.g. Webpack, Rollup):
Copy file name to clipboardExpand all lines: www/content/extensions/ws.md
+24-3Lines changed: 24 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,11 +18,32 @@ Use the following attributes to configure how WebSockets behave:
18
18
event
19
19
or the event specified by [`hx-trigger`])
20
20
21
-
## Install
21
+
## Installing
22
+
23
+
The fastest way to install `ws` is to load it via a CDN. Remember to always include the core htmx library before the extension and [enable the extension](#usage).
An unminified version is also available at https://unpkg.com/htmx-ext-ws/dist/ws.js.
22
32
23
-
```html
33
+
While the CDN approach is simple, you may want to consider [not using CDNs in production](https://blog.wesleyac.com/posts/why-not-javascript-cdn). The next easiest way to install `ws` is to simply copy it into your project. Download the extension from `https://unpkg.com/htmx-ext-ws`, add it to the appropriate directory in your project and include it where necessary with a `<script>` tag.
For npm-style build systems, you can install `ws` via [npm](https://www.npmjs.com/):
36
+
```shell
37
+
npm install htmx-ext-ws
38
+
```
39
+
After installing, you'll need to use appropriate tooling to bundle `node_modules/htmx-ext-ws/dist/ws.js` (or `.min.js`). For example, you might bundle the extension with htmx core from `node_modules/htmx.org/dist/htmx.js` and project-specific code.
40
+
41
+
If you are using a bundler to manage your javascript (e.g. Webpack, Rollup):
0 commit comments