Skip to main content

App Development Best Practices

Best practices for developing O2VEND apps.

Code Organization

App Structure

Organize app files logically:

app/
app.json
snippets/
hook-*.liquid
assets/
app.css
app.js
gateway.js (optional)

Hook Implementation

Efficient Hooks

// Cache expensive operations
const cachedData = processData();
liquid.registerHook('theme_head', () => cachedData);

Error Handling

liquid.registerHook('theme_head', (context) => {
try {
return processHook(context);
} catch (error) {
console.error('Hook error:', error);
return ''; // Return empty string on error
}
});

Security

Input Validation

function validateAppInput(input) {
if (typeof input !== 'object') {
throw new Error('Invalid input');
}
return input;
}

Performance

Minimize Processing

  • Cache results when possible
  • Avoid heavy processing in hooks
  • Defer non-critical operations