Skip to content

Instantly share code, notes, and snippets.

@Richienb
Created January 27, 2019 13:42
Show Gist options
  • Save Richienb/20aa60127cb955d7669a2f6cebcce9ba to your computer and use it in GitHub Desktop.
Save Richienb/20aa60127cb955d7669a2f6cebcce9ba to your computer and use it in GitHub Desktop.
Load external JavaScript libraries in Google Script
// Load JS from HTML file
eval(HtmlService.createTemplateFromFile("<SCRIPT>").getRawContent())
// Load JS from URL
eval(UrlFetchApp.fetch("<SCRIPT>").getContentText())
// Load JS from Google Drive
eval(DriveApp.getFileById("<SCRIPT>").getBlob().getDataAsString())
// Load JS from URL into global namespace
const LIBRARIES = {<SCRIPT REFERENCE>: "<SCRIPT>", <ANOTHER SCRIPT REFERENCE>: "<ANOTHER SCRIPT>"}
Object.keys(LIBRARIES).forEach(function(library) { newFunc = eval(UrlFetchApp.fetch(LIBRARIES[library]).getContentText()); eval('var ' + library + ' = ' + newFunc); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment