Skip to content
Back to skills

607 Best Practices 4fc37192

ASecurity

Detailed best practices with code examples for writing efficient and reliable Apps Script code.

  • 9 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added June 1, 2026
developmentjavascriptgojavaapiperformance

Works with

  • api

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned June 1, 2026

npx -y skills add tools-only/X-Skills --skill 607-best-practices_4fc37192 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 607 Best Practices 4fc37192?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 607 Best Practices 4fc37192
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-607-best-practices-4fc37192/badge)](https://www.skillsdirectory.com/skills/tools-only-607-best-practices-4fc37192)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# Google Apps Script - Best Practices

Detailed best practices with code examples for writing efficient and reliable Apps Script code.

## 1. Use Batch Operations for Performance

Minimise API calls by batching reads and writes:

```javascript
// Good - Single batch read
const values = sheet.getRange('A1:Z1000').getValues();

// Bad - 1000 individual reads
for (let i = 1; i <= 1000; i++) {
  const value = sheet.getRange(`A${i}`).getValue();
}
```

## 2. Cache Frequently Accessed Data

Use CacheService for temporary data (25 min TTL):

```javascript
function getCachedData(key) {
  const cache = CacheService.getScriptCache();
  let data = cache.get(key);

  if (!data) {
    // Fetch from source
    data = expensiveOperation();
    cache.put(key, JSON.stringify(data), 600);  // 10 minutes
  }

  return JSON.parse(data);
}
```

## 3. Handle Errors Gracefully

Implement comprehensive error handling:

```javascript
function safeOperation() {
  try {
    // Operation code
    const range = sheet.getRange('A1');
    range.setValue('Value');
  } catch (error) {
    Logger.log('Error: ' + error.message);
    Logger.log('Stack: ' + error.stack);

    // Notify user
    const ui = SpreadsheetApp.getUi();
    ui.alert('Error: ' + error.message);

    // Log to sheet for audit trail
    const logSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Error Log');
    if (logSheet) {
      logSheet.appendRow([new Date(), error.message, error.stack]);
    }
  }
}
```

## 4. Respect Execution Limits

Scripts have a 6-minute timeout. For large operations:

- Process in batches
- Use triggers to split work
- Implement progress tracking

## 5. Minimise OAuth Scopes

Request only necessary permissions in `appscript.json`:

```json
{
  "oauthScopes": [
    "https://www.googleapis.com/auth/spreadsheets.currentonly",
    "https://www.googleapis.com/auth/script.send_mail"
  ]
}
```

## 6. Use PropertiesService for Persistence

Store configuration and state:

```javascript
function saveConfig(key, value) {
  const props = PropertiesService.getScriptProperties();
  props.setProperty(key, value);
}

function getConfig(key) {
  const props = PropertiesService.getScriptProperties();
  return props.getProperty(key);
}
```

Files in this skill

  • README.md1 KB
  • skill.md2.2 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.