HTML Service: Best Practices

Creating user interfaces with the HTML service follows many of the same patterns and practices as other types of web development. However, there are some aspects that are unique to the Apps Script environment or are otherwise worth highlighting. Below we'll cover some best practices you should keep in mind when developing your own HTML-service UIs.

Separate HTML, CSS, and JavaScript

Keeping all the HTML, CSS, and JavaScript code in one file can make your project difficult to read and develop. While Apps Script does require client-side code to be placed in .html files, you can still separate your CSS and client-side JavaScript into different files and then include them in the main HTML page with a custom function.

The example below defines a custom server-side include() function in the Code.gs file to import the Stylesheet.html and JavaScript.html file content into the Page.html file. When called using printing scriptlets, this function imports the specified file content into the current file. Notice that the included files contain