How to reduce repeatedly and dynamically generated html
Clash Royale CLAN TAG#URR8PPP
How to reduce repeatedly and dynamically generated html
I am in the middle of revising a website and it has a significant problem with rendering time. I looked into what is causing the problem and it turns out that table-generating mechanism that I am using takes way too much time.
As needed data gets queried from DB, the table is dynamically generated in repeated format. (as shown below in the code) Table size increases as scrolling down to bottom. Instead of generating additional table every time additional queries are done, is there any way to get by and reduce the rendering time?
Here is a snippet of HTML structure generated. (there are more than 10000 rows in the same format but with different contents)
Thank you very much for your help in advance!
<tr class="doc_field_vendor_item">
<td width="150px" align="center" class="item">
<div id="invno1127">16011304</div>
</td>
<td width="200px" align="center" class="item">
<div id="invDate1127">2016-01-13</div>
</td>
<td width="130px" align="right" class="item">
<div id="totalDue1127">$ 416.00 </div>
</td>
<td width="130px" align="right" class="item">
<div id="day301127"> $ 416.00 </div>
</td>
<td width="130px" align="right" class="item">
<div id="day31_451127"> </div>
</td>
<td width="130px" align="right" class="item">
<div id="day46_601127"> </div>
</td>
<td width="130px" align="right" class="item">
<div id="day60_Over1127"> </div>
</td>
</tr>
<tr class="doc_field_vendor_item_bg">
<td width="150px" align="center" class="item">
<div id="invno1128">16011305</div>
</td>
<td width="200px" align="center" class="item">
<div id="invDate1128">2016-01-13</div>
</td>
<td width="130px" align="right" class="item">
<div id="totalDue1128">$ 129.60 </div>
</td>
<td width="130px" align="right" class="item">
<div id="day301128"> $ 129.60 </div>
</td>
<td width="130px" align="right" class="item">
<div id="day31_451128"> </div>
</td>
<td width="130px" align="right" class="item">
<div id="day46_601128"> </div>
</td>
<td width="130px" align="right" class="item">
<div id="day60_Over1128"> </div>
</td>
</tr>
How is data queried, on page load or by ajax ?
– Simranjit Singh
Aug 8 at 17:24
Move the width and alignment elements into the item class in the styling. If the
div
inside the td
is not being used for something remove it and just leave the data. Could also move the id
to the td
and get rid of the divs
.– Dave
Aug 8 at 17:30
div
td
id
td
divs
there's no php here (it's misleading) or database code. That makes your question unclear and possibly too broad. Can you update your question so that there is relevant code that we can work with? Otherwise, I'll vote to close as unclear. You could ping
@username
us if you need (more) help.– Funk Forty Niner
Aug 8 at 17:30
@username
Look into Caching pages
– Chad K
Aug 8 at 17:34
1 Answer
1
10000 rows is a lot. You probably don't need to display 10000 rows all at once.
One solution is to paginate the data. Only display 300 rows per page. This is probably easier to do.
Another solution is to render only a fraction of the data initially, and make ajax requests to server side on demand as user scroll down the table. Websites like Facebook and Twitter has this kind of thing. Recall that you can scroll down on these sites infinitely and always load more posts. However, making requests also takes time, which you can optimize by caching some rows ahead of time. For Example, each time you send 1000 rows to the client side, and only render 600 rows on the page, and only make 300 rows visible to the user. When user scrolls down, you render more from cache and make requests to ask for more data from server.
Good idea! I've only considered caching in a longer term. I will definitely give this a try. Thank you :)
– R.Roh
Aug 8 at 20:22
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I assume you're getting all the rows from the DB or getting a small subset of them, many times, then passing each row into some function that generates the table row correct? If so, seeing the code that does that would help us be able to look for anything that might be affecting performance. Otherwise you could try and move the table generation to JS using ajax to make it seem like it's going fast. You could also do a combo of like 1000 rows in php then the rest in JS, though that can be hard to follow later.
– samuraiseoul
Aug 8 at 17:24