0

I've a web app in Google Apps Script where I take a list of restaurants data(name, address, phone etc.) from Google Sheet and show them to my website through AJAX. Currently the resulted data are generated HTML created from Google Apps Script and I was thinking if there's any way to load the list faster. Then I thought of JSON, but I researched about it and found it's not that much of difference in loading time. Here is the HTML code that renders for each of the row data in sheet,

  for (var i=0; i<rng.length; i++)
  {
    if (rng[i][0] != "") {
      html += '<br><div class="row">
                  <div class="col s4">
                      <img class="circle responsive-img" src="img/logos/'+rng[i][0]+'.png" />
                  </div>
                  <div class="col s8">
                      <h5>'+rng[i][1]+'</h5>
                      <p><b>'+rng[i][2]+'</b></p>
                      <p>'+rng[i][3]+'</p>
                      <a class="waves-effect waves-light btn btn-sm red lighten-2" href="menu.html?id='+rng[i][0]+'">See Menu</a>
                  </div>
              </div><hr><br>';
    }
  }

So for each row of data it creates that part of HTML code and returns the entire HTML in my website where I get it through jQuery AJAX. Now, my question is, is the above method better or should I use JSON to get the raw data only & render it through the client-side?

1 Answer 1

2

Sending over prepared HTML should make the site render faster, especially if the client has low-power CPU. But, more than HTML vs JSON, the delay is likely to be due to slow Google Apps Script execution. All that string concatenation should not be happening on every call of doGet, it's a waste of time. Process the data once, each time the spreadsheet is edited (using a trigger), and store the output, be it HTML or JSON, on a separate sheet of the spreadsheet, or in Script Cache. This way doGet will only has to retrieve a string and serve it immediately.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the suggestion. The sheet will be edited once. I just need the data to be shown in my app as fast as possible. If I disclose more, then the app is a phonegap app. What should I do then?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.