如何从外部源加载 javascript 并在 Google Apps Script 中执行它 [英] How to load javascript from external source and execute it in Google Apps Script

查看:28
本文介绍了如何从外部源加载 javascript 并在 Google Apps Script 中执行它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一些 google 应用程序脚本,并希望加载位于我的一台服务器上的 javascript 文件,并能够在 Google Apps 脚本中执行它的功能.

I am building some google apps scripts and want to load a javascript file located on one of my servers and be able to execute it's functions in Google Apps Script.

通过这种方式,我可以与人们共享谷歌应用程序脚本并更新 javascript,而无需他们付出任何努力.(我只会更新我服务器上的版本,然后加载到他们的 Google Apps 脚本中.

This way I can share a google apps script with people and update the javascript without effort needed from their side. (I would just update the version on my server which is then loaded in their Google Apps Script.

有没有办法做到这一点?

Is there a way to do this?

推荐答案

您可以这样做:

eval(UrlFetchApp.fetch("my url").getContentText())

尽管将代码缓存在 ScriptDb 或 CacheService 中并且每 15 分钟左右重新获取一次代码会更快/更有效.

Although it would be a lot faster/more efficient to cache the code in ScriptDb or CacheService and only fetch it fresh every 15 minutes or so.

这篇关于如何从外部源加载 javascript 并在 Google Apps Script 中执行它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆