Slow execution of Bootstrap v4 modal display

It has come to my attention that the modals in Bootstrap show slower as the page's content increases.

When the page is empty, it only takes less than 100ms to show. However, the time it takes significantly increases as more content is added to the page.

I am puzzled by this connection. Can someone clarify why this behavior occurs and offer a solution to speed up the appearance of modals regardless of the page's size?

UPDATE: To see this for yourself, you can visit i.e here and run the command

console.time("modalTime"); $("#exampleModal").modal("show"); console.timeEnd("modalTime");

in the console to observe the duration. Then, add more content to the page using DOM manipulation, and run the command again.

My findings: modalTime : 70 ms on the original page. modalTime : 1208 ms after increasing the page's content tenfold.

Answer №1

Upon further investigation, I have discovered that introducing 50,000 lines of text to the document results in a noticeable delay: https://plnkr.co/edit/hvRAn3wg91GBCPxK2gwb?p=preview

The issue with an extensive DOM structure like this is that any sort of manipulation will require significant time to execute. While it may seem like a jQuery problem, I am inclined to believe otherwise.

To demonstrate that the delay is not directly related to the Modal, I have implemented a simple action where clicking on a button turns its color to red - even this basic operation suffers from the same sluggish performance as opening the modal window.

jQuery(document).ready(function() {
  for (var i = 0; i < 50000; i++) {
    $( "#content" ).append( "This is just some test. This is just some test. This is just some test. This is just some test. This is just some test. This is just some test. This is just some test. This is just some test. This is just some test. <br/>" );
  }

  $("#btnToggleMoadal").click(function(e) {
    $("#exampleModal").modal("show");
    $(this).css({backgroundColor:"red"});
  });
});

Update: In addition, I compared jQuery's onClick versus onClick outside of the DOM - no discernible distinction was observed. https://plnkr.co/edit/483Sk2FGXk9lT8dLZIdo?p=info

Update: It appears my previous statement was inaccurate. The root cause of the performance lag stems from the Bootstrap Modal itself. I suspect the bottleneck lies within the _adjustDialog() function in modal.js.

I suggest raising this issue on https://github.com/twbs/bootstrap/issues and providing the Plunker example for reference.

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

At times, the status code 0 and ready state 0 is returned by Ajax file uploads

After carefully reviewing the following thread: jQuery Ajax - Status Code 0? I was unable to find a definitive solution to my issue. Therefore, I am reaching out here in hopes that someone can guide me in the right direction. In my code, I have an Angul ...

Is the JavaScript file not being stored in the cache?

As I work on optimizing my web application, I am facing a challenge with a javascript file size of approximately 450K even after compressing it. While I intend to redo the javascripting in due time, for now, I need to go live with what I have. Initially, I ...

Is it possible to prevent the text from appearing in the text box when a button is

I have successfully implemented a feature where clicking on the button (click on me) in HTML displays a textbox along with another button (show) on the screen. The text written in the textbox is visible when the show button is clicked. However, after the i ...

JQuery's is() function is returning a true value

I am facing a dilemma with a particular string that can either represent text or an anchor tag with text. I have implemented some logic to always return the text in the following way: $(text).is('a') ? $(text).text() : text; The idea behind ...

Having trouble with jqGrid data format?

Having some trouble with jqGrid and displaying data in a treeview format. The issue is that the 6th item (cid=6) is not appearing in the grid. Additionally, it seems like the 4th item may have subitems, but expanding that branch reveals nothing. I cannot f ...

Experiencing browser crashes following the incorporation of asynchronous functions into a JavaScript file. Seeking solutions to resolve this

In my recent project, I developed a basic online store application using vanilla javascript and ES6 classes. The shop items are stored in a JSON file which I used to populate the user interface. To implement functions like "addToCart", "quantityChange", a ...

Enable lightbox functionality prior to all images being fully loaded

I have a large number of images (thumbnails) on my website and I am using the Featherlite lightbox plugin. However, when I click on one of the loaded images while they are still loading, the lightbox does not work as expected. Instead of opening in a modal ...

Accessing fields from other sources in ng-repeat can be accomplished by utilizing special syntax within the ng-repeat directive

I have a unique challenge where I need to utilize the firstkey from one AngularJS model, firstcollection, as an index value in another collection called anothercollention. Essentially, I want to iterate over the values in anothercollention based on the k ...

Sorting through a list of strings by checking for a specific character within each string

After spending years dabbling in VBA, I am now delving into Typescript. I currently have an array of binary strings Each string represents a binary number My goal is to filter the array and extract all strings that contain '1' at position X I ...

I am utilizing jQuery's AJAX function with a datatype of HTML to extract a specific portion of the incoming data

This is the JavaScript function I am working with: function getCountryRegions() { var postData = "id="+$("#selectedCountryId").val(); $.ajax({ url:"/region", data: postData, dataType:"html", type:"POST", ...

What is the best way to notify a user one minute before their cookie expires using PHP and JavaScript?

I need a solution to alert my logged-in users one minute before their cookie expires, allowing them to save content in the CMS. Any ideas on how I can make this happen? In my auth file, I have configured the following: setcookie("USERNAME", $user,time()+ ...

Can you determine the sequence in which these code statements are placed on the call stack?

I am a beginner in the world of Javascript and currently seeking to grasp a better understanding of how the JS execution engine operates. I am aware that any asynchronous code statement is pushed onto the call stack and then promptly removed, allowing it t ...

Tips for accessing various JSON objects from a JSON document

My task involves extracting specific information from a JSON file using AJAX and jQuery. The structure of my JSON data is as follows: "Footwear": { "Adidas": [ { "id" : 0, &q ...

Tips for verifying the presence of a Firestore Document reference within a JavaScript array of Document references

I am currently dealing with a document that contains an array field storing references to other documents. Upon fetching the document data and verifying if a document reference exists within the array, I consistently receive a result indicating that it is ...

iOS Simulator offers a range of both offline and online events for testing purposes

I have been working on a phonegap 3.3 application that incorporates angularjs. When testing the application in my browser, I am successfully able to detect and respond to 'offline' and 'online' events. However, when I switch to the ios ...

Passing events between sibling components in Angular 2Incorporating event emission in

Having some trouble emitting an event from one component to another sibling component. I've attempted using @Output, but it seems to only emit the event to the parent component. Any suggestions? ...

Refreshing table cell contents following a table sort operation

I have a dynamic HTML table that retrieves data from MySQL. Every 5 seconds, I use AJAX to check for any changes in the MySQL table and update specific cells in the HTML table. Now, I am interested in incorporating a jQuery plugin for table sorting. You c ...

"The Ajax function for replacing a div upon change event is not functioning properly

I am having an issue with my select box using the onchange event, <select class="form-control" onchange="getval(this.value,'<?php echo $prd->pr_id;?>','ajax<?php echo $key?>','<?php echo $key ?>')"&g ...

Adobe Acrobat does not run JavaScript code in documents that are submitted for electronic signatures

Lately, I have been experiencing issues with pdfs that contain embedded javascript. The strange thing is that the javascript functions perfectly in the Acrobat Pro DC app but fails to execute when the document is sent for signature. To troubleshoot, I cre ...

Arrange the array based on the order of the enumeration rather than its values

Looking to create an Array of objects with enum properties. export enum MyEnum { FIXTERM1W = 'FIXTERM_1W', FIXTERM2W = 'FIXTERM_2W', FIXTERM1M = 'FIXTERM_1M', FIXTERM2M = 'FIXTERM_2M', FIXTERM3M = 'FIX ...