Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lazy <option> loading

Assuming I have a select like this:

<select size="4">
  <option id="1">Please wait ...</option>
  <option id="2">Please wait ...</option>
  <option id="3">Please wait ...</option>
  <option id="4">Please wait ...</option>
  <option id="5">Please wait ...</option>
</select>

I should see a List of 4 elements having a scrollbar on the right.

What i like to do now is to load the text via ajax if the option becomes visible somehow (scrolling and/or initial).

EDIT:

At the end, I do not load them lazy because of the huge metadata transfer. This is the request I must upload (send to the server):

huge upload for small download

This is inacceptable for the lazy-load of single elements.

like image 993
Grim Avatar asked Feb 19 '17 11:02

Grim


People also ask

Should I enable lazy loading?

You should always use lazy loading for the images below the fold. As we explained, lazy loading will reduce the real and perceived loading time. User experience will benefit from it — and you users will thank you.

What is lazy loading and how it works?

Lazy loading is a technique for waiting to load certain parts of a webpage — especially images — until they are needed. Instead of loading everything all at once, known as "eager" loading, the browser does not request certain resources until the user interacts in such a way that the resources are needed.

Does lazy loading improve performance?

Lazy-loading images and video reduces initial page load time, initial page weight, and system resource usage, all of which have positive impacts on performance.


1 Answers

I'm sorry for my bad English, but as I'm understanding this question I can present this solution:

$(document).ready(function(){
  $('select').on('scroll', function(){
    var sel = $(this);
    var lasto = sel.find('option:last');
    var s = sel.position().top + sel.height();
    var o = lasto.height() + lasto.position().top - 4;
    setTimeout(function(){
      if(o < s){console.log('We need AJAX!');}
    }, 2200);
  });
});

Link

like image 64
Choo Hwan Avatar answered Nov 15 '22 21:11

Choo Hwan