When we use HTML in the Google Apps Script project, in order to show the values from the Google Apps Script side, the HTML template is used. When I used the HTML template with a large value, I understood that the process cost can be reduced by devising a script. In this report, I would like to introduce the process cost of the HTML template using the benchmark.
A great feature of Google Apps Script is the ability to create and serve custom HTML, often used to interface data you have in Google Workspace such as Google Sheets. Google highlight a coupe of different ways you can mix Apps Script code and HTML. Some of these ways are better in terms of process time and this report from Kanshi Tanaike highlights the cost of calling Apps Script functions as scriptlets in HTML templates. The good news is you can avoid delays in your web app rendering by making asynchronous calls with
google.script.run, which you can read more about in Google’s best practices documentation.
Update: I’ve replicated this benchmark (smaller dataset) with
google.script.run and it was only marginally slower (0.3s) than the ‘create HTML table with Google Apps Script’:
Source: Benchmark: Process cost for HTML Template using Google Apps Script
Member of Google Developers Experts Program for Google Workspace (Google Apps Script) and interested in supporting Google Workspace Devs.
What they don’t cover, is … what if I get a (JSON) Array using google.script.run and then iterate over it (say with jQuery) and append divs to a container div. Would be nice to know.
I ran some tests along the lines of what you suggested (smaller sample) and it is slower but not by much (on average 0.3s slower than ‘create HTML table with Google Apps Script’). One benefit of the approach you suggest is you can render the UI quicker with a ‘loading’ image/text which might be useful if how you are getting/prepping your data takes time.
Method and results here https://docs.google.com/spreadsheets/d/1H09cm6kMGk7xDw7JZ-m_wYNr1KXP8k28qeaT4SpSlcA/edit?usp=sharing