Skip to content

Commit e1fa94d

Browse files
committed
added auto for CDN
1 parent 371af69 commit e1fa94d

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ A minimalistic library to create fast and reactive Web pages.
2929
* developers enhanced mode runtime debugging sessions
3030

3131

32-
<sub>see [codepen](https://codepen.io/WebReflection/pen/VYvbddv?editors=0010)</sub>
32+
<sub>test in [codepen](https://codepen.io/WebReflection/pen/VYvbddv?editors=0010)</sub>
3333

3434
```js
3535
import { html, signal } from 'https://esm.run/uhtml';
@@ -165,11 +165,12 @@ import { render, html } from 'https://esm.run/uhtml/debug';
165165
// https://cdn.jsdelivr.net/npm/uhtml/dist/dev/dom.js
166166

167167
// automatic prod/dev version on ?dev or ?debug
168+
import { render, html } from 'https://esm.run/uhtml/auto';
168169
import { render, html } from 'https://esm.run/uhtml/cdn';
169170
// https://cdn.jsdelivr.net/npm/uhtml/dist/prod/cdn.js
170171
```
171172

172-
Using `https://esm.run/uhtml/cdn` or the fully qualified `https://cdn.jsdelivr.net/npm/uhtml/dist/prod/cdn.js` URL provides an automatic switch to *debug* mode if the current page location contains `?dev` or `?debug` or `?debug=1` query string parameter plus it guarantees the library will not be imported again if other scripts use a different *CDN* that points at the same file in a different location.
173+
Using `https://esm.run/uhtml/cdn` (or */auto*) or the fully qualified `https://cdn.jsdelivr.net/npm/uhtml/dist/prod/cdn.js` URL provides an automatic switch to *debug* mode if the current page location contains `?dev` or `?debug` or `?debug=1` query string parameter plus it guarantees the library will not be imported again if other scripts use a different *CDN* that points at the same file in a different location.
173174

174175
This makes it easy to switch to *dev* mode by changing the location from `https://example.com` to `https://example.com?debug`.
175176

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
"types": "./types/dom/index.d.ts",
2929
"description": "uhtml default browsers' export"
3030
},
31+
"./auto": {
32+
"import": "./dist/prod/cdn.js",
33+
"types": "./types/dom/index.d.ts",
34+
"description": "uhtml browsers' export with automatic dev/prod switch on ?dev or ?debug pages' URLs"
35+
},
3136
"./cdn": {
3237
"import": "./dist/prod/cdn.js",
3338
"types": "./types/dom/index.d.ts",

src/dom/cdn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const resolve = ({ protocol, host, pathname }) => {
22
const dev = /[?&](?:dev|debug)(?:=|$)/.test(location.search);
33
let path = pathname.replace(/\+\S*?$/, '');
4-
path = path.replace(/\/cdn(?:\/|\.js\S*)$/, '/');
4+
path = path.replace(/\/(?:auto|cdn)(?:\/|\.js\S*)$/, '/');
55
path = path.replace(/\/(?:dist\/)?(?:dev|prod)\//, '/');
66
return `${protocol}//${host}${path}dist/${dev ? 'dev' : 'prod'}/dom.js`;
77
};

0 commit comments

Comments
 (0)