You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

PoulChr's avatar
PoulChr
Helpful | Level 6
6 years ago

Several xmlhttprequest: very slow

My R-pi based weatherstation collects 48 measurements over an hour.
When a new hour starts, these are saved in a file and uploaded to dropbox, 
- and a new collection begins.
When a new day starts, the existing files are overwritten.

The files are created as a code segment for javascript as follows:

var array1 = [-0.06,18.6,47,64,1014.1, ......, 0.41,18.61,46.82,1013.6];
These is named: 1.js, 2.js etc.
In my web browser, I can then use these as include files for javascript.
Thus:

<script src="https://dl.dropbox.com/s/xyzxyzxyzxyzxyz/1.js?raw=1" type = "text / javascript"> </ script>
I then plot these data in graphs that cover a day.
This works fine and is very fast even though I need to download 24 files.
I have now tried to build 24 CSV data files and then download them with xmlhttprequest.
This is extremely slow. (Have tried both sync and async)

Why?
And what can I do instead?

Sincerely Poul Christoffersen

  • Thanks! I just tried this, and the network requests to the Dropbox links aren't running particularly slowly for me. How are you measuring this? What step exactly is running slow?

    I do notice that you have `result` scoped outside any particular function, and you're doing `result+= xhr.responseText`, meaning that each call will yield the concatenation of the results of all previous calls, in addition to the current call. Is that what you intended? The size of that may grow relatively large, especially if the csv files are large to begin with, which could slow down execution. You may want to scope the `result` variable to inside your `onreadystatechange` function, and just pass just the current result to `addTxt`, if that makes sense for what you're building.

    Anyway, that aside, I don't see any particular issues with the Dropbox service itself here, but please let me know if I'm missing something.

    Also, one other note, you're writing these links to access 'dl.dropbox.com', but that will result in a redirect anyway. If you want to avoid that, you should use 'dl.dropboxusercontent.com' instead. Be aware that accessing file data programmatically via either of these domains isn't officially supported anyway. (You're supposed to use the 'raw=1' parameter, for instance, as documented here, but that may not work for your use case.)

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    I'm not aware of any reason that using XMLHttpRequest in particular should be very slow. Can you share the code you're using and how you're measuring this?

    • PoulChr's avatar
      PoulChr
      Helpful | Level 6

      My 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 content="text/html; charset=utf-8" http-equiv="Content-Type" />

      <title>Untitled 1</title>

       <script>

      var result;

      var  files = [                                        //   "dl" and not "www" ! ! !

        "https://dl.dropbox.com/s/xyzxyzxyzxyzxyzx/0.csv", …….

      , "https://dl.dropbox.com/s/xyzxyzxyzxyzxyzx/23.csv"

       ];

       function readDbox() {

         addTxt("Starting download..");

         var url;

         var xhr = new XMLHttpRequest();

         for (let i=0; i<files.length; i++) {

            url = files[i];

            addTxt(url);

            xhr.onreadystatechange = function() {

             if (xhr.readyState === 4 && xhr.status === 200) {

                 result+= xhr.responseText;

               }

            }

            xhr.open("GET", url, true); // false => sync

            xhr.send();

         }

         addTxt(result) ;

      }

      function addTxt(str) { document.getElementById("txtA").innerHTML+= str+"\n";      }

       </script> 

      </head>

       <body>

         <textarea id="txtA" style="width: 286px; height: 154px"  ></textarea><br/><br/>

         <input id="btn1" type="button" value="Get file" onclick="readDbox()"/>

      </body>

       </html>

       

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        Thanks! I just tried this, and the network requests to the Dropbox links aren't running particularly slowly for me. How are you measuring this? What step exactly is running slow?

        I do notice that you have `result` scoped outside any particular function, and you're doing `result+= xhr.responseText`, meaning that each call will yield the concatenation of the results of all previous calls, in addition to the current call. Is that what you intended? The size of that may grow relatively large, especially if the csv files are large to begin with, which could slow down execution. You may want to scope the `result` variable to inside your `onreadystatechange` function, and just pass just the current result to `addTxt`, if that makes sense for what you're building.

        Anyway, that aside, I don't see any particular issues with the Dropbox service itself here, but please let me know if I'm missing something.

        Also, one other note, you're writing these links to access 'dl.dropbox.com', but that will result in a redirect anyway. If you want to avoid that, you should use 'dl.dropboxusercontent.com' instead. Be aware that accessing file data programmatically via either of these domains isn't officially supported anyway. (You're supposed to use the 'raw=1' parameter, for instance, as documented here, but that may not work for your use case.)

About Discuss Dropbox Developer & API

Node avatar for Discuss Dropbox Developer & API

Make connections with other developers

795 PostsLatest Activity: 11 days ago
193 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!