|
6 | 6 | import six |
7 | 7 |
|
8 | 8 | from _plotly_utils.optional_imports import get_module |
9 | | -from plotly.io._utils import validate_coerce_fig_to_dict |
| 9 | +from plotly.io._utils import validate_coerce_fig_to_dict, plotly_cdn_url |
10 | 10 | from plotly.offline.offline import _get_jconfig, get_plotlyjs |
11 | 11 | from plotly import utils |
12 | 12 |
|
@@ -61,10 +61,16 @@ def to_html( |
61 | 61 | fully self-contained and can be used offline. |
62 | 62 |
|
63 | 63 | If 'cdn', a script tag that references the plotly.js CDN is included |
64 | | - in the output. HTML files generated with this option are about 3MB |
65 | | - smaller than those generated with include_plotlyjs=True, but they |
66 | | - require an active internet connection in order to load the plotly.js |
67 | | - library. |
| 64 | + in the output. The url used is versioned to match the bundled plotly.js. |
| 65 | + HTML files generated with this option are about 3MB smaller than those |
| 66 | + generated with include_plotlyjs=True, but they require an active |
| 67 | + internet connection in order to load the plotly.js library. |
| 68 | +
|
| 69 | + If 'cdn-latest', a script tag that always references the latest plotly.js |
| 70 | + CDN is included in the output. |
| 71 | + HTML files generated with this option are about 3MB smaller than those |
| 72 | + generated with include_plotlyjs=True, but they require an active |
| 73 | + internet connection in order to load the plotly.js library. |
68 | 74 |
|
69 | 75 | If 'directory', a script tag is included that references an external |
70 | 76 | plotly.min.js bundle that is assumed to reside in the same |
@@ -266,12 +272,15 @@ def to_html( |
266 | 272 | require_start = 'require(["plotly"], function(Plotly) {' |
267 | 273 | require_end = "});" |
268 | 274 |
|
269 | | - elif include_plotlyjs == "cdn": |
| 275 | + elif include_plotlyjs == "cdn" or include_plotlyjs == "cdn-latest": |
| 276 | + cdn_url = plotly_cdn_url() |
| 277 | + if include_plotlyjs == "cdn-latest": |
| 278 | + cdn_url = plotly_cdn_url(cdn_ver="latest") |
270 | 279 | load_plotlyjs = """\ |
271 | 280 | {win_config} |
272 | | - <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>\ |
| 281 | + <script src="{cdn_url}"></script>\ |
273 | 282 | """.format( |
274 | | - win_config=_window_plotly_config |
| 283 | + win_config=_window_plotly_config, cdn_url=cdn_url |
275 | 284 | ) |
276 | 285 |
|
277 | 286 | elif include_plotlyjs == "directory": |
@@ -417,10 +426,16 @@ def write_html( |
417 | 426 | fully self-contained and can be used offline. |
418 | 427 |
|
419 | 428 | If 'cdn', a script tag that references the plotly.js CDN is included |
420 | | - in the output. HTML files generated with this option are about 3MB |
421 | | - smaller than those generated with include_plotlyjs=True, but they |
422 | | - require an active internet connection in order to load the plotly.js |
423 | | - library. |
| 429 | + in the output. The url used is versioned to match the bundled plotly.js. |
| 430 | + HTML files generated with this option are about 3MB smaller than those |
| 431 | + generated with include_plotlyjs=True, but they require an active |
| 432 | + internet connection in order to load the plotly.js library. |
| 433 | +
|
| 434 | + If 'cdn-latest', a script tag that always references the latest plotly.js |
| 435 | + CDN is included in the output. |
| 436 | + HTML files generated with this option are about 3MB smaller than those |
| 437 | + generated with include_plotlyjs=True, but they require an active |
| 438 | + internet connection in order to load the plotly.js library. |
424 | 439 |
|
425 | 440 | If 'directory', a script tag is included that references an external |
426 | 441 | plotly.min.js bundle that is assumed to reside in the same |
|
0 commit comments