Skip to content

This repo shows patterns you can use to elevate Python web apps via streaming HTML and htmx

Notifications You must be signed in to change notification settings

PyHAT-stack/web-async-patterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Proof of concept: Streaming HTML with Python

Inspired by Taylor Hunt's incredible explanation of how he turned a slow Fortune 20 webapp into a snappy experience, even on a cheap Android phone, I made this repo to show the current capability of Django to render streaming HTML.

This technique is best used to improve the perceptual performance for expensive database queries or slow API calls. The idea is that the user could start seeing the page come together while the query or calls are happening. Rendering of the page will pause once it hits the block that is waiting on the data, but being able to see the page render should make the user feel as though the website is performing faster.

Referencing Taylor's blog post:

Both of these pages show search results in 2.5 seconds. But they sure don't feel the same.

This concept shows how a recommendation engine takes some time to recommend four products, based for the current user.

Viewing the concept

Open a terminal at the root of this project and type the following:

python -m venv .venv --prompt stream_python
# If in Windows:
.venv/Scripts/activate
# otherwise
source .venv/bin/
# Then
pip install -r requirements.txt
uvicorn stream.asgi:application --reload 

You can then click the link in the terminal or go to http://127.0.0.1:8000 to view the page.

Thanks

Thanks to https://github.com/fajar7xx/ecommerce-template-tailwind-1 for the HTML template.

About

This repo shows patterns you can use to elevate Python web apps via streaming HTML and htmx

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published