Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Browser (Chromium/Firefox) becomes unresponsive for 1-2sec after file dialog

How can I improve this code in order to remove unresponsivness / page lag after selecing a file from file dialog and clicking OK?

I've been testing files with sizes around 50-100 KB

function handleFileSelect(evt) {
  var files = evt.target.files; // FileList object

  // files is a FileList of File objects. List some properties.
  var output = [];
  for (var i = 0, f; f = files[i]; i++) {
    output.push('<li><strong>', escape(f.name), '</strong> (', f.type || 'n/a', ') - ',
      f.size, ' bytes, last modified: ',
      f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a',
      '</li>');
  }
  document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
}

document.getElementById('files').addEventListener('change', handleFileSelect, false);
<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>

I'm running this page on localhost and I'm using SSD

Thanks

like image 997
Joelty Avatar asked Apr 03 '20 11:04

Joelty


1 Answers

Your code is perfectly fine. Try measuring the performance to investigate further:


enter image description here

like image 181
Joe - Elasticsearch Handbook Avatar answered Oct 21 '22 03:10

Joe - Elasticsearch Handbook