Enhancing speed on an extensive list without a set height/eliminating the need for virtualization

My webapp includes a feature that showcases exhibitors at an expo. The user can click on "Exhibitors" in the navigation bar to access a page displaying all the exhibitors. Each exhibitor may have different details, some of which may or may not contain data (such as Booth, Videos, etc). To accommodate this variability, fixed row heights were eliminated for better UX.

The problem arises when there are over 500 exhibitors, causing the DOM to freeze while rendering them all. This process can take quite a bit of time, especially on mobile devices. Virtualization seems challenging without fixed row heights. I am now seeking ideas on how to enhance performance without significantly compromising the user experience.

Here's what I've experimented with so far:

  1. Batching the data-binding: Dividing the list into chunks and processing them through a queue with delays to prevent overwhelming execution.
  2. On-demand loading: Initially binding and rendering around 50 exhibitors, then dynamically loading and appending additional chunks as users scroll.

Any thoughts or suggestions would be greatly appreciated!

Answer №1

When dealing with a list of 500 elements, lazy loading is often the most efficient approach. If the data size from the request is not substantial, you can fetch all necessary data in one go (if it's from a web service) and incrementally add to the list as needed. Alternatively, you can make individual requests for batches of items.

It's crucial to optimize how you add elements to your list by only appending them to the DOM once, rather than creating and adding HTML for each element separately. This strategy minimizes the number of times the DOM has to reflow, significantly boosting performance.

Instead of:

for (i = 0; i < length; i++) {
    $(container).append($('<p>new element</p>'));
}

You should do this:

html = '';
for (i = 0; i < length; i++) {
    html += '<p>new element</p>';
}
$(container).append($(html));

-----Update------ Below is some code I've utilized previously (assuming jQuery is being used)

function contentNearBottom(container, child, threshold) {
    var total_height, current_scroll, visible_height;

    current_scroll = container.scrollTop();
    visible_height = container.height();
    total_height = child.height();

    if (threshold < 0) threshold = 0;

    return ((total_height - threshold) <= (current_scroll - visible_height));
}

function lazyLoadMessages() {
    if (contentNearBottom($("div.content"), $("div.content > ul"), 2500)) {
        // load more data
    }
}

Add this in document ready function

$(document).on('scrollstart scrollstop', 'div.content', function(event) {
    lazyLoadMessages();
});

The HTML structure

<div class="content">
    <ul>
    </ul>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using jQuery to implement interactive hover effects on individual items within a list

I'm currently developing a project that involves displaying speech bubbles next to each list item when hovered over. These speech bubbles contain relevant information specific to the item being hovered on. To achieve this functionality, I've crea ...

Top align a flexbox layout with three columns

I am facing a challenge in aligning my 3 columns at the top with multiple "rows". When I apply the CSS property align-items: flex-end;, I achieve the desired layout, but the elements are aligned at the bottom. However, if I attempt to use align-items: flex ...

Wrapping an anchor tag with a div in Codeigniter

Can a div tag be used inside an anchor function? I have a div with the following CSS: #first{ opacity:0; } Now, I want to include it in my anchor element. Here is the code snippet: <?php if(is_array($databuku)){ echo '<ol>&l ...

What is the best way to format a string to display the second value in the string?

I have successfully combined the currency and value columns into one column displaying USD 20000. Now I am looking to format the value string to appear as USD 20,000. However, I am unsure of how to incorporate property.DisplayFormatString into the second s ...

Update input field value with data retrieved via ajax call in AngularJS

My current approach involves using AngularJS directives for Bootstrap in order to create an edit form on a Bootstrap modal when the user clicks on the edit button from a list of items. Here is the code I have implemented: HTML: <div class="modal-heade ...

Developing JavaScript code for preventing blocking

Managing a large number of file requests from a tiny server has been a challenge for me. With approximately 100 files to fetch, my current approach using JavaScript's forEach loop is causing the server to crash due to the heavy load. links.forEach ...

"Assure that setTimeout will be executed within the then method in

Within an Immediately Invoked Function Expression (IFFE), I am returning a Promise. The first thing that is logged is first, followed by third, and then second. Despite having the setTimeout inside the then block, shouldn't everything within it be exe ...

HTML and Python synchronize perfectly when handling date formatting

Here is a code snippet I am working with: {% for x in fixtures %} <TR style="display:block" onclick="team_visibility('match{{ forloop.counter }}');"> <TD> {{ x.fixturedate }}</TD> ...

How can I show the HTML text "<ahref>" in a UITextView on iOS?

Is there a way to show HTML tags like <a> in a textview? As an example, here is some code: Hello good morning <a href=\"1\">USER1</a> and <a href=\"13\">USER2</a> ...

Enhance Your Website with Php Jquery Autocomplete Feature!

In the main page, there is an autocomplete input field along with an [ADD button]. When the user clicks on the add button, they are redirected to a page to add a new record. After saving the new record, the user is then redirected back to the main page. ...

Tips for generating a unique user validation hash or token

I have a registration endpoint in my express app where users need to verify their email before account activation. I'm struggling with creating a hash for the verification link. I considered using JWT, but it feels like an overcomplicated solution. Is ...

What is the best way to design an element that exceeds the size of my physical body

I am currently working on creating a table that needs to be larger than the body and centered. Let me provide some more information. Below is my simplified HTML code : <body> <div id="one"> <div> <tab ...

Fill the image with width using Mat

While working on creating cards using Angular Materials, I encountered an issue where the image was not filling up the space as desired. The red area in the image indicates where I want the image to take up space. HTML: <mat-card (click)="optionP ...

Using Angular and Jade to pass an array from a controller to script tags

I am trying to figure out how to access an array in my controller and display it accurately within the <script> tags in my jade template. For instance: Controller.js $scope.myArray = ["item1","item2"]; Within my index.jade: script. var clien ...

Showing RSS feed on Vue.js interface

I am trying to integrate a Google Alert feed into my Vue.js application, specifically on the "Dashboard.vue" component using "Feed.vue". I have successfully implemented this feature in JavaScript, but I am facing difficulties converting it to Vue.js. Curr ...

Looking for a way to include the current page's HTML code when exporting a CSV file

Here is the HTML code showcasing the Export button: <form method="post" name="download_csv" class="pull-right" enctype="multipart/form-data"> <button type="submit" name="Export" class="btn btn-success" >Export to excel</button> < ...

my goal is to transform this text into the background

For my latest project, I want the entire page that I've coded to be integrated into the <body> section with endless scrolling ability. Additionally, I need the loop that I created to remain fixed when scrolling so that I can easily place my con ...

Ways to detect scrolling activity on the v-data-table module?

Are you looking for a way to detect scrolling events on the v-data-table component in Vuetify framework? I am referring to the scenario where the table has a fixed height, causing the table body to scroll. <v-data-table fixed-header :height=400 : ...

The formatting of the list is not being correctly displayed in the Ajax Jquery list

Trying to dynamically generate an unordered list from XML onto a jQuery mobile page has been a bit of a challenge for me. While I can display the items on the page, the styling never seems to work properly, only showing up as plain text with blue links. Is ...

Create a new column in Material UI Grid by adding an empty div element instead of using padding

I'm currently getting acquainted with Material UI Grid and I am interested in adding an empty column (a blank space on the right of the first element) without utilizing padding. How can this be achieved? Here's a snippet of the code being discus ...