PyScript and Pyodide: Managing Stale Cache in <py-script> src Files
0 reputation · 05 Aug 2021, 09:11 UTC
The goal is to guarantee that a Python script referenced via a <py-script src="..."> tag runs the most recent version after the source file changes on the server. PyScript caches fetched scripts in Pyodide’s virtual filesystem and reuses them across reloads unless the URL or cache validator indicates a newer version. This depends on HTTP headers such as ETag or Last‑Modified and on the <py-config cache> attribute, which defaults to true.
Documentation does not clearly state whether PyScript automatically invalidates cached <py-script> src files when the server updates the file with a new ETag or Last‑Modified header, or whether developers must use manual cache busting, such as appending a query‑parameter version, to force a fresh fetch.
Given these constraints, what is the recommended strategy for ensuring fresh execution of an updated <py-script> src file on each page load? 1) Does PyScript honor ETag/Last‑Modified headers to invalidate its cache automatically? 2) Is setting <py-config cache="false"> or adding a URL query parameter the best approach, or is there a different method? 3) How does the <py-config cache> setting interact with HTTP caching across PyScript releases?