I have a webapp that displays a lot of interactive JS data tables and graphs in a single page (about 50-60). The page rendering required takes a lot of time (Chrome WebTools show about 20-25 seconds in the "Rendering" State from ajax response to completion) since each interactive element is a standalone "widget".
Because the types and structure of the tables/graphs is mostly constant and only the data varies, I think it's very inefficient to have the client render them each time. It would be better to send the client a rendered page and only populate the data where needed.
I've read about Headless Chrome and Puppeteer but they are NodeJS modules. I was wondering if there was a way to incorporate this server-side rendering of JS in a Python-based backend.
You can render React components server-side with python-react or with python-react-v8 .
Installation:
pip install react
Usage:
from react.render import render_component
rendered = render_component(
'/path/to/component.jsx',
{
'foo': 'bar',
'woz': [1,2,3],
}
)
print(rendered)
More about the render server .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.