-
Notifications
You must be signed in to change notification settings - Fork 1.5k
-
Currently, if PyScript is included on a page, it will always auto-initialize - even if there is no desire to render/evaluate any Python code; even if there is no py-script on the page (acceptable, for when wanting to manually eval/execute code after page load). Also, if PyScript is included multiple times in a single page, it tries to initialize pyodide multiple times.
In some cases, it may be necessary to blindly include the PyScript src reference on a page, even though it may not be used (adding as a general reference, for if/when it is needed). It also may be added directly in a particular code block that uses it (in a CMS like WordPress, SquareSpace, or Confluence), and there may be multiple of those code blocks included on a single page.
Propose adding some attribute to the script tag, script within the onload attribute of the script tag, or value in the py-config (first instance on the page) that can stop auto-initialization/download/execution of pyodide, packages, etc. along with mechanisms to manually trigger such as needed/appropriate- for example, in a separate code block after the page fully loads, and only if there is at least one py-script block on the page.
Workaround for time-being:
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" /> <!-- <script defer src="https://pyscript.net/latest/pyscript.js"></script> --> <script> window.addEventListener('load', function () { if (document.querySelector('py-script')) { if (!window.pyscriptLoaded) { window.pyscriptLoaded = true; const el = document.createElement('script'); el.src = 'https://pyscript.net/latest/pyscript.js'; document.body.appendChild(el); } } }, { once: true }) </script>
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
with PyScript Next now available for preview as @pyscript/core
module, nothing gets bootstrapped until at least one script on the page is present ... so we already fixed that but not in "classic pyscript".
<script type="module" src="https://unpkg.com/@pyscript/core"></script>
Beta Was this translation helpful? Give feedback.