diff --git a/02_chatbot/README.md b/02_chatbot/README.md index 30970ee..fb4aa6a 100644 --- a/02_chatbot/README.md +++ b/02_chatbot/README.md @@ -133,6 +133,10 @@ Using `Transfer-Encoding: chunked` is a way to send a response in chunks, which We can use the [transfer-encoding-chunked](https://www.npmjs.com/package/htmx-ext-transfer-encoding-chunked) htmx extension to enable chunked transfer of the response. To do this, add the requisite headers by passing `exts='chunked-transfer'` to the FastHTML constructor, and then use the `hx_ext="chunked-transfer"` attribute in the form. +```python +app = FastHTML(..., exts="chunked-transfer") +``` + ```python Form(hx_post=send, hx_target="#chatlist", hx_swap="beforeend", hx_ext="chunked-transfer", hx_disabled_elt="#msg-group") ``` diff --git a/02_chatbot/chunked_transfer.py b/02_chatbot/chunked_transfer.py index 6a8f78e..7113a28 100644 --- a/02_chatbot/chunked_transfer.py +++ b/02_chatbot/chunked_transfer.py @@ -4,11 +4,11 @@ import asyncio # Set up the app, including daisyui and tailwind for the chat component -hdrs = (picolink, - Script(src="https://cdn.tailwindcss.com"), - Link(rel="stylesheet", href="https://cdn.jsdelivr.net/npm/daisyui@4.11.1/dist/full.min.css")) +tlink = Script(src="https://cdn.tailwindcss.com"), +dlink = Link(rel="stylesheet", href="https://cdn.jsdelivr.net/npm/daisyui@4.11.1/dist/full.min.css") +hdrs = (picolink, tlink, dlink) -app = FastHTML(hdrs=hdrs, ct_hdr=True, cls="p-4 max-w-lg mx-auto", live=True, debug=True) +app = FastHTML(hdrs=hdrs, ct_hdr=True, cls="p-4 max-w-lg mx-auto", exts="chunked-transfer", live=True, debug=True) @app.route("/{fname:path}.{ext:static}") async def get(fname:str, ext:str):