Skip to content

Commit 0e1a2c7

Browse files
authored
Merge pull request #3121 from davidbrochart/jsdelivr_cdn
Change CDN from unpkg to jsdelivr
2 parents 5de5abe + ccfff33 commit 0e1a2c7

File tree

9 files changed

+25
-23
lines changed

9 files changed

+25
-23
lines changed

docs/source/embedding.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ html_template = """
123123
124124
<!-- Load IPywidgets bundle for embedding. -->
125125
<script
126-
data-jupyter-widgets-cdn="https://cdn.jsdelivr.net/npm/"
126+
data-jupyter-widgets-cdn="https://unpkg.com/"
127127
data-jupyter-widgets-cdn-only
128-
src="https://unpkg.com/@jupyter-widgets/html-manager@*/dist/embed-amd.js"
128+
src="https://cdn.jsdelivr.net/npm/@jupyter-widgets/html-manager@*/dist/embed-amd.js"
129129
crossorigin="anonymous">
130130
</script>
131131
@@ -179,7 +179,7 @@ In this example, we used a Python string for the template, and used the
179179
documents, you may want to use a templating engine like
180180
[Jinja2](http://jinja.pocoo.org/).
181181

182-
We also change the CDN from its default of unpkg to use jsdelivr by setting the
182+
We also change the CDN from its default of jsdelivr to use unpkg by setting the
183183
`data-jupyter-widgets-cdn` attribute.
184184

185185
What's more, we only load modules from the CDN by setting the
@@ -263,14 +263,14 @@ documentation. An illustration of this is the http://jupyter.org/widgets
263263
gallery.
264264

265265
The widget embedder attempts to fetch the model and view implementation of the
266-
custom widget from the npm CDN https://unpkg.com by default. The URL that is requested
266+
custom widget from the npm CDN https://cdn.jsdelivr.net/npm by default. The URL that is requested
267267
for, e.g. the `bqplot` module name, with the semver range `^2.0.0` is
268268

269-
`https://unpkg.com/bqplot@^2.0.0/dist/index.js`
269+
`https://cdn.jsdelivr.net/npm/bqplot@^2.0.0/dist/index.js`
270270

271271
which holds the webpack bundle for the bqplot library.
272272

273-
While the default CDN is using https://unpkg.com it can be configured by
273+
While the default CDN is using https://cdn.jsdelivr.net/npm it can be configured by
274274
setting the optional `data-jupyter-widgets-cdn` attribute for script tag which loads `embed-amd.js`,
275275
as shown in the example above.
276276

docs/source/migration_guides.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ values of the `version` field in your `package.json`).
147147

148148
The `_model_module_version` and `_view_module_version` are used to find your
149149
JavaScript bundle when embedding widgets. The embed manager will look for the
150-
bundle at `https://unpkg.com/<module-name>@<module-version>/dist/index.js`
150+
bundle at `https://cdn.jsdelivr.net/npm/<module-name>@<module-version>/dist/index.js`
151151
when it finds a widget.
152152

153153
### Updating embedded widgets
@@ -159,7 +159,7 @@ There are now two options for embedding widgets in an HTML page outside of the n
159159
If you are just embedding the standard widgets that come with ipywidgets, then you can simply include the following script tag:
160160

161161
```html
162-
<script src="https://unpkg.com/@jupyter-widgets/html-manager@*/dist/embed.js" crossorigin="anonymous"></script>
162+
<script src="https://cdn.jsdelivr.net/npm/@jupyter-widgets/html-manager@*/dist/embed.js" crossorigin="anonymous"></script>
163163
```
164164

165165
If you want to use a specific version of the embedder, you replace the `@*` with a semver range, such as `@^0.9.0`
@@ -175,7 +175,7 @@ In order to embed third-party widgets, you can use the RequireJS-based embedding
175175

176176
Then include the following script, which defines the embedding libraries and runs the function to render widgets:
177177
```html
178-
<script src="https://unpkg.com/@jupyter-widgets/html-manager@*/dist/embed-amd.js" crossorigin="anonymous"></script>
178+
<script src="https://cdn.jsdelivr.net/npm/@jupyter-widgets/html-manager@*/dist/embed-amd.js" crossorigin="anonymous"></script>
179179
```
180180
If you want to use a specific version of the embedder, you replace the `@*` with a semver range, such as `@^0.9.0`
181181

examples/web1/manager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ class WidgetManager extends ManagerBase {
2020
let failedId = err.requireModules && err.requireModules[0];
2121
if (failedId) {
2222
console.log(
23-
`Falling back to unpkg.com for ${moduleName}@${moduleVersion}`
23+
`Falling back to jsDelivr for ${moduleName}@${moduleVersion}`
2424
);
2525
window.require(
2626
[
27-
`https://unpkg.com/${moduleName}@${moduleVersion}/dist/index.js`
27+
`https://cdn.jsdelivr.net/npm/${moduleName}@${moduleVersion}/dist/index.js`
2828
],
2929
resolve,
3030
reject

examples/web2/manager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ class WidgetManager extends ManagerBase {
2020
let failedId = err.requireModules && err.requireModules[0];
2121
if (failedId) {
2222
console.log(
23-
`Falling back to unpkg.com for ${moduleName}@${moduleVersion}`
23+
`Falling back to jsDelivr for ${moduleName}@${moduleVersion}`
2424
);
2525
window.require(
2626
[
27-
`https://unpkg.com/${moduleName}@${moduleVersion}/dist/index.js`
27+
`https://cdn.jsdelivr.net/npm/${moduleName}@${moduleVersion}/dist/index.js`
2828
],
2929
resolve,
3030
reject

examples/web4/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ replace
1313

1414
with
1515

16-
`<script src="https://unpkg.com/@jupyter-widgets/html-manager/dist/embed.js" crossorigin="anonymous"></script>`
16+
`<script src="https://cdn.jsdelivr.net/npm/@jupyter-widgets/html-manager/dist/embed.js" crossorigin="anonymous"></script>`
1717

1818
If you need a specific version of the HTML widget manager, you can include a
1919
semver range. For example:
2020

21-
`<script src="https://unpkg.com/@jupyter-widgets/html-manager@^0.8.0/dist/embed.js" crossorigin="anonymous"></script>`
21+
`<script src="https://cdn.jsdelivr.net/npm/@jupyter-widgets/html-manager@^0.8.0/dist/embed.js" crossorigin="anonymous"></script>`
2222

2323
## Try it
2424

ipywidgets/embed.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
{view_spec}
5959
</script>"""
6060

61-
DEFAULT_EMBED_SCRIPT_URL = 'https://unpkg.com/@jupyter-widgets/html-manager@%s/dist/embed.js'%__html_manager_version__
62-
DEFAULT_EMBED_REQUIREJS_URL = 'https://unpkg.com/@jupyter-widgets/html-manager@%s/dist/embed-amd.js'%__html_manager_version__
61+
DEFAULT_EMBED_SCRIPT_URL = 'https://cdn.jsdelivr.net/npm/@jupyter-widgets/html-manager@%s/dist/embed.js'%__html_manager_version__
62+
DEFAULT_EMBED_REQUIREJS_URL = 'https://cdn.jsdelivr.net/npm/@jupyter-widgets/html-manager@%s/dist/embed-amd.js'%__html_manager_version__
6363

6464
_doc_snippets = {}
6565
_doc_snippets['views_attribute'] = """
@@ -81,7 +81,7 @@
8181
full description.
8282
embed_url: string or None
8383
Allows for overriding the URL used to fetch the widget manager
84-
for the embedded code. This defaults (None) to an `unpkg` CDN url.
84+
for the embedded code. This defaults (None) to a `jsDelivr` CDN url.
8585
requirejs: boolean (True)
8686
Enables the requirejs-based embedding, which allows for custom widgets.
8787
If True, the embed_url should point to an AMD module.

packages/html-manager/src/libembed-amd.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import * as libembed from './libembed';
55

6-
let cdn = 'https://unpkg.com/';
6+
let cdn = 'https://cdn.jsdelivr.net/npm/';
77
let onlyCDN = false;
88

99
// find the data-cdn for any script tag, assuming it is only used for embed-amd.js
@@ -54,7 +54,7 @@ function moduleNameToCDNUrl(moduleName: string, moduleVersion: string): string {
5454
* @param moduleName The name of the module to load..
5555
* @param version The semver range for the module, if loaded from a CDN.
5656
*
57-
* By default, the CDN service used is unpkg.com. However, this default can be
57+
* By default, the CDN service used is jsDelivr. However, this default can be
5858
* overriden by specifying another URL via the HTML attribute
5959
* "data-jupyter-widgets-cdn" on a script tag of the page.
6060
*
@@ -95,7 +95,7 @@ export function requireLoader(
9595
*
9696
* @param element (default document.documentElement) The element containing widget state and views.
9797
* @param loader (default requireLoader) The function used to look up the modules containing
98-
* the widgets' models and views classes. (The default loader looks them up on unpkg.com)
98+
* the widgets' models and views classes. (The default loader looks them up on jsDelivr)
9999
*/
100100
export function renderWidgets(
101101
element = document.documentElement,

packages/html-manager/webpack.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ var rules = [
5656
];
5757

5858
var publicPath =
59-
'https://unpkg.com/@jupyter-widgets/html-manager@' + version + '/dist/';
59+
'https://cdn.jsdelivr.net/npm/@jupyter-widgets/html-manager@' +
60+
version +
61+
'/dist/';
6062

6163
module.exports = [
6264
{

widgetsnbextension/src/embed_widgets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var embed_widgets = function() {
4242
'',
4343
'<!-- Load require.js. Delete this if your page already loads require.js -->',
4444
'<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" crossorigin="anonymous"></script>',
45-
'<script src="https://unpkg.com/@jupyter-widgets/html-manager@*/dist/embed-amd.js" crossorigin="anonymous"></script>',
45+
'<script src="https://cdn.jsdelivr.net/npm/@jupyter-widgets/html-manager@*/dist/embed-amd.js" crossorigin="anonymous"></script>',
4646
'<script type="application/vnd.jupyter.widget-state+json">',
4747
data,
4848
'</script>',

0 commit comments

Comments
 (0)