简体   繁体   中英

Django Bootstrap form is slow to render, how can I speed up?

I have a large form (20 fields) that is taking forever to block render in Django + bootstrap-toolkit, as it can be seen in the following graphs:

时间分解

Also see this block breakdown graph.

What I've tried...

  • Cache the view. The csrf token always makes it a new view thus it never actually caches.
  • Split the form out into it's own block content then cache that block while keeping the csrf tags on the outside of the field. Django had a hard time rendering that and the POST buttons wouldn't work.

I'm out of ideas and need some outside perspective on how to work around this.

I got it loading much faster by doing the following.

I pre-rendered out the form with the zillion block requests.
Opened browser requested the form.
Copied the form HTML code.
Created new html file with the pre-render HTML form.
Changed the 'VIEW''s GET request to use the new pre-rendered form HTML. Added CRSF token just inside the form.

Response time was reduced from 5 seconds to .50 ms.

It's important to note you won't be able to use the cache decorated on that view. You can use the <% cache %> template tags on the new HTML file with the form.

Hope this helps!

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM