|
6 | 6 | import six
|
7 | 7 |
|
8 | 8 | from plotly.io._utils import validate_coerce_fig_to_dict
|
9 |
| -from plotly.offline.offline import _get_jconfig, get_plotlyjs |
| 9 | +from plotly.offline.offline import _get_jconfig, get_plotlyjs, get_plotlyjs_version |
10 | 10 | from plotly import utils
|
11 | 11 |
|
12 | 12 |
|
@@ -58,10 +58,16 @@ def to_html(
|
58 | 58 | fully self-contained and can be used offline.
|
59 | 59 |
|
60 | 60 | If 'cdn', a script tag that references the plotly.js CDN is included
|
61 |
| - in the output. HTML files generated with this option are about 3MB |
62 |
| - smaller than those generated with include_plotlyjs=True, but they |
63 |
| - require an active internet connection in order to load the plotly.js |
64 |
| - library. |
| 61 | + in the output. The url used is versioned to match the bundled plotly.js. |
| 62 | + HTML files generated with this option are about 3MB smaller than those |
| 63 | + generated with include_plotlyjs=True, but they require an active |
| 64 | + internet connection in order to load the plotly.js library. |
| 65 | +
|
| 66 | + If 'cdn-latest', a script tag that always references the latest plotly.js |
| 67 | + CDN is included in the output. |
| 68 | + HTML files generated with this option are about 3MB smaller than those |
| 69 | + generated with include_plotlyjs=True, but they require an active |
| 70 | + internet connection in order to load the plotly.js library. |
65 | 71 |
|
66 | 72 | If 'directory', a script tag is included that references an external
|
67 | 73 | 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_ver = get_plotlyjs_version() |
| 277 | + if include_plotlyjs == "cdn-latest": |
| 278 | + 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="https://cdn.plot.ly/plotly-{cdn_ver}.min.js"></script>\ |
273 | 282 | """.format(
|
274 |
| - win_config=_window_plotly_config |
| 283 | + win_config=_window_plotly_config, cdn_ver=cdn_ver |
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