Some of the PyScript WASM files are large. For example, pyodide.asm.wasm is ~9.5 MB. Correctly setting up your web server to serve these files takes some consideration. You should configure several items in your web server. This article covers Apache 2.4 running on Ubuntu 20.04. There are similar configurations for Nginx.

I plan to write another article showing how to configure a PyScript application to specify the PyScript origin using the <py-config> directive.

Support the WASM Mime Type

If the Mime type application/wasm is not set up, you might see errors like this:

For Ubuntu, edit the file /etc/apache2/mods-enabled/mime.conf. Add the following line:

Enable WASM Compression

WASM files are compressible. Properly setting up compression for WASM files can reduce network bandwidth and download time.

For Ubuntu, edit the file /etc/apache2/mods-enabled/deflate.conf. Add the following line:

Precompress WASM Files

Apache tries to compress files on the fly at each request. This will consume CPU cycles. Precompress WASM files to .wasm.gz and use content negotiation (Multiviews).

Multiviews is a per-directory option. Multiviews can be set with an Options directive within a <Directory>, <Location> or <Files> section in apache2.conf.

Edit /etc/apache2/apache2.conf. Add the following lines within one of the supported sections (usually <Directory>):


Hopefully, this article provided you with some new information about PyScript and how to deliver those files to your consumers.

More Information

Photography Credit

I write free articles about technology. Recently, I learned about which provides free images. The image in this article is courtesy of Harvey Sapir at Pexels.