executablebooks / sphinx-thebe

A Sphinx extension to convert static code into interactive code cells with Jupyter, Thebe, and Binder.
https://sphinx-thebe.readthedocs.io/en/latest/
MIT License
28 stars 15 forks source link

ENH: Lazy load thebe javascript #41

Closed choldgraf closed 2 years ago

choldgraf commented 2 years ago

Description

This lazily loads the Thebe javascript bundle when the initThebe function is triggered (usually, when somebody clicks the "launch Thebe" button).

It does this by appending a script to the page header via javascript, rather than adding it to the Sphinx HTML bundle when it is created.

Rationale

In most cases, people won't need Thebe loaded on a page because they'll only have one or two pages of their docs site that have Thebe-relevant content. Rather than loading Thebe each time, this will ensure it's loaded only when actively needed. It will take a bit longer to load when people click the button, but in most cases the size of the inputs/outputs loading will likely quickly be larger than the original thebe javascript payload, so this shouldn't hurt the UX much.

Behavior changes

There's one default change with this PR: thebe will now be loaded lazily by default, whereas before it was loaded automatically on all pages by default.

closes https://github.com/executablebooks/sphinx-thebe/issues/34 closes https://github.com/executablebooks/jupyter-book/issues/1014 closes https://github.com/executablebooks/sphinx-thebe/issues/32