0

This is the code:

mainobject = $("#MainObject");
topBasis = mainobject.offset().top;
mainHeight = mainobject.height();
leftBasis = mainobject.offset().left;
mainWidth = mainobject.width();

But because of the fact that the MainObject is really large it takes a few seconds to execute this piece of code. Is there any way to make it faster?

Joris Janssen
  • 64
  • 1
  • 10
  • 3
    `MainObject is really large` ? How does that make a difference ? – Rayon Jan 25 '16 at 10:41
  • There must be something else which is causing the issues..can you share a live demo where one could re-produce this issue.. – Rayon Jan 25 '16 at 10:49
  • you can `detach()` object before perform operation if it is really large looping on object. I don't think so it takes too time may be so other issue. – Parth Trivedi Jan 25 '16 at 10:49
  • No, by logging the time I have found that this piece of code is the problem, MainObject is about 5000 in lenght in minimum so because of that it takes a few seconds to load the whole object into mainobject – Joris Janssen Jan 25 '16 at 10:54

1 Answers1

0

You could add that piece of code right before closing the body tag. This way, you win a couple of seconds because while the page loads, your script runs in the background.

You could read this post for a way to improve the performance. What I would recommend, is some sort of pagination. You bring what you expect the user to request and this way, for example once every 5-10 objects, you bring others, but for some time, you will have them already.

Community
  • 1
  • 1
Simply Me
  • 1,579
  • 11
  • 23