Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Manual control of bootstrapping/initialization #1623

kulogix started this conversation in Proposals
Discussion options

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>
You must be logged in to vote

Replies: 1 comment

Comment options

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>
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /