gpt4 book ai didi

google-apps-script - HTML 服务速度慢

转载 作者:行者123 更新时间:2023-12-05 01:10:08 27 4
gpt4 key购买 nike

我正在尝试使用带有 HTML 服务的模态对话框为 Google 文档创建一个附加组件,但是从运行我的脚本到对话框窗口中发生某些事情之间的时间非常慢。

这是一个非常简单的例子。 (这有点 hack-y 因为从 Example.html 调用 foo 会覆盖第一个日志)

// Code.gs
function openDialog() {
var html = HtmlService.createHtmlOutputFromFile('Example')
.setSandboxMode(HtmlService.SandboxMode.IFRAME);

Logger.log("hi");
var temp = Logger.getLog();

DocumentApp.getUi()
.showModalDialog(html, temp);
}

function foo() {
Logger.log("bye");
}

// Example.html
<script>google.script.run.foo();</script>

如果我运行它,第一个日志和第二个日志之间会有大约 4 秒的差异。事情就是这样吗?

最佳答案

简短回答:是的。您的方法是调用服务器端函数的最佳方法之一。

长答案:根据 documentation , 尝试 loading data asynchronously .它说——

Templated HTML can be used to quickly build simple interfaces, but its use should be limited to ensure your UI is responsive. The code in templates is executed once when the page is loaded, and no content is sent to the client until the processing is complete. Having long-running tasks in your scriptlet code can cause your UI to appear slow.

您也可以尝试在 UI 中提供微调器/预加载器,这应该有助于改善用户体验。

它还推荐我们Use the HTML5 document type declaration

If your page is served using the newer IFRAME sandbox mode, make sure to include the following snippet of code at the top of you HTML file.

<!DOCTYPE html>

希望这对您有所帮助。

关于google-apps-script - HTML 服务速度慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34604706/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com