Are there any workarounds for the relatively long loading times?

Hi :wave:

I tried running the examples on on a local file server, it appears it takes like 0.7-1.5 seconds for a page to load on my system (which is perhaps a bit on the upper end). Every time I refresh the page or enter a new page using Pyscript the loading time is about the same.

Is it possible to cache the pyscript runtime to only load the first time you visit the website on a webbrowser session? Are there any other ways that you can decrease loading times?


There are three factors at play:

  1. PyScript file location.
  2. Time to load the PyScript files (about 20 MB).
  3. Time to initialize Pyodide.

You can determine where and how long each phase takes using the browser debugger.

To improve the file load time:

  1. Cache the files in the browser. PyScript now sets the HTTP cache headers so that the browser can cache the files. The browser debugger will confirm if this is the case.
  2. Implement WebWorker caching. This uses some of the techniques from PWAs. When configured correctly, an Internet connection is not required.

To improve the file initialization time:

  1. This will require work from the Pyodide team and there is nothing I am aware of that we can do in an application except to run on a faster machine. I think that the biggest factor here is the time to initialize the Wasm files.

The key is to determine where the files are coming from (CDN or local browser cache), how long it takes to read the files, and how long to initialize PyScript/Pyodide.

1 Like