Movatterモバイル変換


[0]ホーム

URL:


Skip to content
❤️ Support Starlette viasponsors! 📚 Do you like the new docs?Let us know!

Server push

Starlette includes support for HTTP/2 and HTTP/3 server push, making itpossible to push resources to the client to speed up page load times.

Request.send_push_promise

Used to initiate a server push for a resource. If server push is not availablethis method does nothing.

Signature:send_push_promise(path)

  • path - A string denoting the path of the resource.
fromstarlette.applicationsimportStarlettefromstarlette.responsesimportHTMLResponsefromstarlette.routingimportRoute,Mountfromstarlette.staticfilesimportStaticFilesasyncdefhomepage(request):"""    Homepage which uses server push to deliver the stylesheet.    """awaitrequest.send_push_promise("/static/style.css")returnHTMLResponse('<html><head><link rel="stylesheet" href="/static/style.css"/></head></html>')routes=[Route("/",endpoint=homepage),Mount("/static",StaticFiles(directory="static"),name="static")]app=Starlette(routes=routes)

[8]ページ先頭

©2009-2026 Movatter.jp