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

Struggling to Position Advertisement in CSS

I've been struggling to properly center a div using CSS. Adding text-align: center; doesn't seem to do the trick. The issue can be found in the top advert on this website: . Do you have any suggestions? Here's some sample code: HTML: &l ...

Encountered a problem when injecting the angularjs $location service

I'm having some trouble getting the $location service to work in this code snippet: <script type="text/javascript> var $injector = angular.injector(['ng', 'kinvey', 'app.constants']); $in ...

How to remove an extra horizontal scroll bar from a fixed-header HTML table?

While working on updating my HTML tables to have fixed headers, I followed online examples that suggest making table-layout fixed, thead and tbody blocks, setting height constraints for tbody, and applying overflow-y to tbody. The result is functional as m ...

Access the most recent state value with React's Context API

Trying out the React context API, Take a look at the someComponent function where I pass the click event (updateName function) to update the value of state.name from the GlobalProvider function. After updating state.name, it reflects in the browser but t ...

I'm curious as to why a webpage tends to load more quickly when CSS files are loaded before script files. Can anyone shed some

While watching a video, I came across some concepts that were a bit difficult for me to grasp. The video mentions that scripts are 'serialized' and can block subsequent files from loading. According to this explanation, Script 1 would load first ...

Performing a dynamic animation by toggling the class of an element with "classList.toggle" in JavaScript

I have been attempting to incorporate a fade animation using CSS when altering the class of the input and label elements within a form by utilizing the classList.toggle method in JavaScript. I'm puzzled as to why my code isn't producing the desir ...

What is the best way to retrieve a PHP response using jQuery's .load method

Here are some sample codes for better understanding. This code is from my file named some3.php: <head> <script src="jquery-1.7.2.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function(){ ...

Tips for accessing an Angular service from different Angular controllers

I am a beginner with angular js and I am currently exploring ways to call the service provided in the code snippet below from a controller. The service is defined as follows. app.factory('myappFactory', ['$http', function($http) { v ...

Create a speech bubble using only CSS, featuring a partially see-through background and a stylish border

I wish to design a speech bubble using only CSS. There are specific requirements I need to meet: It should adjust its size based on content with some padding or a set size. The background color must be semi-transparent. You must be able to define a borde ...

What is the best way to access an item within an item using HTML and AngularJS?

I attempted to retrieve a value from two dynamic objects using AngularJS. <div ng-controller="SampleController"> <div> {{item['111']['price']}} </div> within the SampleController $scope.item={111:{price:"232"},112:{ ...

I'm having trouble getting my JavaScript code to run, can anyone offer any advice on what

Can you provide assistance with this code? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv=" ...

Table design with fixed left columns and header that adjust to different screen sizes

After reading various articles on this issue, I have been unable to find a solution. Most of the examples I've come across feature tables with a single row for the header and rows that consist of just one row, similar to a calendar. My table, on the o ...

How to fetch an image from a web API using JavaScript

I have recently entered the world of web development and I am facing an issue where I am trying to retrieve a Bitmap Value from a web api in order to display it on an HTML page using JavaScript. However, despite my efforts, the image is not getting display ...

What is the process of extracting values from a Range Slider in JQuery - IonRangeSlider?

Is there a way to retrieve the values from an ion.rangeSlider component when the slider is changed? Below is the jQuery code I am currently using: function rangeSlider() { var $range = $(".js-range-slider"); $range.ionRangeSlider({ type: "single", ...

Setting up Webpack for react-pdf in a Next.js application

In my Next.js application, I am utilizing the react-pdf library to generate and handle PDF files on the client side without involving the server. However, I am facing challenges in setting up Webpack for Next.js as I lack sufficient expertise in this area. ...

Tips on avoiding quotation marks in a Less variable containing a color identifier

I'm currently working on an HTML/CSS project where I aim to establish classes for labels and texts based on their color. For instance: .text-red{ color: red; } .label-white{ color: white; } In order to achieve this, my approach involves cr ...

Redis: Unable to establish a connection as net.connect is not recognized as a

I'm struggling to integrate Redis with nodejs Encountering issues during execution Despite using the same code, I am facing this error: Here's my code snippet: import { createClient } from 'redis' export const client = createClient({ ...

What occurs when you use the statement "import someModuleName from someModule" in JavaScript?

When reusing a module in multiple places, you typically use module.exports = yourModuleClassName to make the module exportable. Then, when you want to use it elsewhere, you can simply import it with import yourModuleClassName from 'yourmodulePath&apos ...

Error: The method of promise.then is not recognized as a function

Having an issue with Rxjs v5 while attempting to run http.get requests one after the other in sequential order. The error message received is TypeError: promise.then is not a function. Below is the code snippet in question: var http = require('ht ...

Calling an Ajax request from a subdomain to the main domain

I'm currently facing some challenges with making an ajax cross-scripting request using jquery. The situation is as follows: I am on a subdomain named test.example.com and I'm making an ajax call to www.example.com/action like so: $.ajax({ ur ...