Pick the right Plotly.js bundle for your Plotly.py HTML export
Compare CDN, directory, and inline Plotly.js bundling in plotly.io.write_html to choose the right export for offline dashboards, email, or production.
28 Jul 2026, 20:31 UTC

The blank chart problem
You export a Plotly chart to HTML, send it to a colleague, and open it on a train with no Wi-Fi. The page loads, but the chart area is empty. The browser console shows a failed request to a content delivery network (CDN), which is a network of servers that hosts files so browsers can download them quickly.
This happens because plotly.io.write_html defaults to loading Plotly.js from a remote CDN. If the reader cannot reach that network, the chart cannot draw. The useful takeaway is to choose the include_plotlyjs argument based on where the file will be opened, not just how small you want the HTML to be.
What include_plotlyjs actually controls
Plotly.py offers four common ways to handle the Plotly.js library when exporting a figure:
include_plotlyjs='cdn': The HTML contains a script tag that downloads Plotly.js from a CDN when the page opens. The file is tiny, but it requires internet access at render time.include_plotlyjs='directory': Plotly.js is written into a sibling folder next to the HTML file. The HTML stays lightweight, and the chart works offline as long as the folder stays alongside it.include_plotlyjs=True: The full Plotly.js library is embedded directly inside the HTML. The result is a single self-contained file, but it can be several megabytes.full_html=False: Returns only an HTML div fragment. It is not standalone; the host page must load Plotly.js separately.
Plotly Express and Graph Objects figures both support these options because they share the same plotly.io serialization layer.
Worked example: export the same figure three ways
Run this in a local Python environment with Plotly installed. No administrative permissions are required if you have write access to the output directory. Replace fig with your own Plotly Express or Graph Objects figure.
import os
import plotly.express as px
fig = px.scatter(x=[1, 2, 3], y=[4, 5, 6], title='Sample export')
# CDN: smallest file, needs internet
fig.write_html('chart_cdn.html', include_plotlyjs='cdn')
# Directory: offline, keeps a sibling library folder
fig.write_html('chart_dir.html', include_plotlyjs='directory')
# Inline: one self-contained file, larger size
fig.write_html('chart_inline.html', include_plotlyjs=True)
# Quick size comparison
for name in ['chart_cdn.html', 'chart_dir.html', 'chart_inline.html']:
print(name, os.path.getsize(name), 'bytes')
Expected checks after running:
chart_cdn.htmlshould be the smallest file and contain a remote script URL.chart_dir.htmlshould be accompanied by a newly created folder containing aplotly-*.min.jsfile.chart_inline.htmlshould be much larger and contain the library text inside the HTML itself.
Risks: write_html overwrites existing files with the same name. Inline files can exceed email attachment limits or load slowly on mobile networks.
Trade-offs and limitations
| Mode | Offline? | Single file? | Typical size | Best for |
|---|---|---|---|---|
| CDN | No | Yes | Tiny | Internal tools with reliable internet |
| Directory | Yes | No | Small HTML plus library folder | Offline dashboards, shared drives |
| Inline | Yes | Yes | Several megabytes | Email attachments, single-file distribution |
| full_html=False | No* | No | Tiny fragment | Pages that already load Plotly.js |
*The fragment still requires Plotly.js to be loaded by the host page.
Default CDN URLs and serialization behavior can vary across Plotly.py versions. Pin Plotly in production, for example with plotly==5.x.x in your requirements file, to avoid unexpected changes to exported HTML.
Verify before you ship
- Export the figure with each
include_plotlyjsoption. - Disable Wi-Fi or enable airplane mode.
- Open each HTML file in a browser.
- Confirm the chart renders only for directory and inline exports.
- Check file size with
os.path.getsizeand confirm the inline file fits your delivery channel.
If the chart is blank offline, regenerate it with include_plotlyjs='directory' or True. Because writing files changes state, keep backups of prior exports; write_html has no built-in undo.