penzai.treescope.html_compression.compress_html(html_src: str, include_preamble: bool = True, loading_message: str | None = None) str[source]#

Compresses HTML source to an equivalent compressed JavaScript <script> tag.

This function compressed and then encodes the given HTML contents into an equivalent JavaScript source tag, which can then be output in place of the original HTML.

  • html_src – The HTML we want to compress.

  • include_preamble – Whether to include the preamble script. Can be disabled if you plan to compress multiple HTML fragments and display them one at a time; to ensure scripts execute in the right order, only the first should include the preamble.

  • loading_message – Message to display while the HTML is decompressing.


An HTML snippet containing a <script> tag that will render the same as the given HTML when loaded in a modern browser.