Use project Javascript and CSS files in a Google Apps Script web app?

后端 未结 5 997
南方客
南方客 2020-12-08 08:40

If I create a simple HTML web app in Google Apps Script, like this:

function doGet() {
    return HtmlService.createHtmlOutputFromFile(\"index.html\");
}
         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 09:15

    Here is a workaround I have found useful:

    1. Add this function to your server-side Javascript:

      function getContent(filename) {
          return HtmlService.createTemplateFromFile(filename).getRawContent();
      }
      
    2. Add a second 'html' file to your project that contains only the JS or CSS surrounded by

    3. Now you can include the script in your main HTML template like this:

      
      

    This way, you can have your JS and CSS split into as many files as you like and keep them all accessible from within the Apps Script project.

提交回复
热议问题