Best Practices
Essential guide for building production-ready TELA applications with size constraints, performance optimization, and DERO blockchain integration.
β οΈ
Critical Size Constraints TELA has strict size limitations that are absolute requirements. Never exceed these limits or deployment will fail.
π Size Constraints (CRITICAL)
File Size Limits
| File Type | Content Limit | Total Limit | Status |
|---|---|---|---|
| TELA-DOC-1 | 18.00 KB | 19.20 KB | β οΈ Absolute max |
| TELA-INDEX-1 | 9 KB recommended | 11.64 KB max | β οΈ May break updates |
| Shard Size | 17,500 bytes | - | β οΈ Auto-split point |
π«
Actual Error Messages from parse.go:
"docCode size is to large, max %.2fKB""DOC SC size is to large, max %.2fKB""contract exceeds max INDEX install size by %.2fKB"
Size Planning Guide
| File Size | Action | Strategy | Compression |
|---|---|---|---|
| < 10 KB | β Deploy | Direct deployment | Optional |
| 10-15 KB | β οΈ Monitor | Standard workflow | Consider .gz |
| 15-18 KB | β οΈ Critical | Optimize first | Required |
| 18 KB+ | β Too large | Split into modules | Use DocShards |
π― Core Principles
HTML-First Development
TELA Principle: HTML-First, JavaScript-Minimal
Write fast, zippy static HTML-based applications using proven patterns from tela_tests/app1.
Proven JavaScript Patterns
// β
PROVEN PATTERN - Based on working tela_tests/app1
let socket;
const applicationData = {
"id": Array.from({length:64},()=>Math.floor(Math.random()*16).toString(16)).join(''),
"name": "Your TELA Application",
"url": "http://localhost:" + location.port
};
function connectWebSocket() {
socket = new WebSocket("ws://localhost:44326/xswd");
socket.addEventListener("open", function(event) {
socket.send(JSON.stringify(applicationData));
});
}β‘ Size Optimization Quick Reference
Optimization Techniques Comparison
| Technique | Before | After | Savings |
|---|---|---|---|
| Variable Names | calculateDEROAmount() | calcDERO() | ~40% |
| String Concatenation | 4 statements | 1 statement | Overhead reduction |
| Function Compression | 127 bytes | 64 bytes | 50% |
| CSS Shorthand | 4 properties | 1 property | 75% |
| Template Compression | Multi-line | Single-line | ~30% |
CSS Optimization
| What | β Avoid | β Optimize |
|---|---|---|
| Properties | margin-top: 1rem; margin-right: 0; margin-bottom: 1rem; margin-left: 0; | margin: 1rem 0; |
| Colors | rgba(255, 255, 255, 1) | #fff |
| Formatting | Multi-line verbose | Single-line compressed |
| Selectors | Long descriptive names | Short functional names |
JavaScript Optimization
| What | β Avoid | β Optimize |
|---|---|---|
| Variables | currentBlockHeight, transactionHashList | h, txs |
| Functions | Separate helpers | Combined operations |
| Templates | Multi-line template literals | Single concatenation |
| Objects | applicationName, connectionTimeout | name, timeout |
| Styles | Repeated inline styles | Shared constants |
Quick Examples:
// Variable shortening: 47 bytes β 28 bytes
function calcDERO(a) {
return a ? (parseFloat(a)/1e12).toFixed(6)+' DERO' : '0.000000 DERO';
}
// Template compression: Multi-line β Single-line
var t = '<div class="card"><h2>'+title+'</h2><p>'+content+'</p></div>';
// Shared styles: Repeated β Constant
var s = 'background:rgba(0,0,0,0.2);border:1px solid rgba(82,200,219,0.3);';
function renderCard() { return '<div style="'+s+'">Card</div>'; }HTML Optimization
| What | β Avoid | β Optimize |
|---|---|---|
| Attributes | id="main-container" style="display: block;" | id="main" |
| Whitespace | Formatted with indentation | Compressed single-line |
| Structure | Verbose nested divs | Minimal semantic HTML |
π¦ Module Organization
| Scenario | Strategy | File Count | Example |
|---|---|---|---|
| < 18 KB total | Single file | 1 | Simple apps |
| 18-35 KB | Split by feature | 2-3 | Core + UI modules |
| 35 KB+ | Full modular split | 4+ | Use DocShards system |
Single File Pattern:
({
name: 'simple-app',
version: '1.0.0',
init: function() { /* ... */ },
render: function() { /* ... */ }
});Multi-Module Pattern:
// core.js (15KB) - Core logic
// ui.js (12KB) - UI components
// data.js (10KB) - Data handlingπ DERO Blockchain Integration
XSWD Protocol Requirements
π«
MANDATORY: XSWD Protocol Only ALL blockchain data must come from DERO daemon via XSWD WebSocket protocol. External APIs are forbidden.
| Data Source | β Allowed | β Forbidden |
|---|---|---|
| DERO Daemon | xswd.call('DERO.GetInfo') | - |
| Wallet via XSWD | xswd.call('GetBalance') | - |
| External APIs | - | fetch('https://api.example.com') |
| CDN Libraries | - | <script src="https://cdn..."> |
// β
CORRECT: XSWD data fetching
async function getBlockData(height) {
const block = await xswd.call('DERO.GetBlock', { height });
return block;
}
// β FORBIDDEN: External API calls
// fetch('https://api.example.com/block/' + height) // NEVERReal Data Only Policy
// β
CORRECT: Live blockchain data
const balance = await xswd.call('GetBalance');
const deroAmount = balance.balance / 100000;
// β FORBIDDEN: Demo or placeholder data
// const demoBalance = 123.45678; // NEVER USE FAKE DATAπ« No External Dependencies
| Dependency Type | β Forbidden | β Solution |
|---|---|---|
| CSS Frameworks | Bootstrap, Tailwind CDN | Custom minimal CSS |
| JavaScript Libraries | jQuery, Chart.js CDN | Lightweight custom implementations |
| Fonts | Google Fonts CDN | System fonts or embedded |
| Icons | Font Awesome CDN | SVG icons or emoji |
// β
GOOD: Custom lightweight implementation
const MiniChart = {
draw(canvas, data) {
const ctx = canvas.getContext('2d');
const max = Math.max(...data);
// Minimal chart drawing code...
}
};
// β AVOID: Heavy external libraries
// import Chart from 'chart.js'; // Too large for TELAβ‘ Performance Targets
| Metric | Target | Critical |
|---|---|---|
| Load Time | < 2 seconds | Required |
| Animation FPS | 60 fps | Smooth |
| Memory Footprint | Minimal | Long-running apps |
Efficient DOM Updates:
// β
GOOD: Batch updates
function updateBlockList(blocks) {
const html = blocks.map(b =>
`<div class="b" data-h="${b.height}">...</div>`
).join('');
document.getElementById('blocks').innerHTML = html;
}
// β AVOID: Individual manipulations
blocks.forEach(block => {
const div = document.createElement('div'); // Slow
container.appendChild(div);
});π Security & Privacy
| Practice | β Good | β Avoid |
|---|---|---|
| Data Storage | Local preferences only | Sensitive wallet data |
| External Tracking | None | Analytics services |
| User Input | Sanitize all inputs | Direct injection |
| Content Security | CSP compliant | Inline scripts from user data |
// β
GOOD: Secure patterns
const SecureTELAApp = {
savePreference(key, value) {
localStorage.setItem(`tela-app-${key}`, JSON.stringify(value));
},
executeSecurely(userInput) {
return userInput.replace(/[<>'"&]/g, ''); // Sanitize
}
};β What Works in TELA
Proven JavaScript Features
| Feature | Status | Example |
|---|---|---|
ES6 let/const | β Works | let socket; const data = {}; |
| Arrow Functions | β Works | document.addEventListener('mousemove', (e) => {...}) |
| Template Literals | β Works | `${title}` |
| String Concatenation | β Works | "http://localhost:" + location.port |
| Traditional Functions | β Works | function connect() {...} |
| Event Listeners | β Works | socket.addEventListener('open', fn) |
CSS Features That Work
| Feature | Status | Example |
|---|---|---|
| CSS Variables | β Works | :root { --color: #52c8db; } |
| Animations | β Works | @keyframes spin { 0% { ... } } |
| Grid/Flexbox | β Works | display: grid; grid-template-columns: ... |
| Gradients | β Works | background: linear-gradient(...) |
| Transforms | β Works | transform: rotate(360deg) |
π Development Checklist
Quick Development Checklist - Use this for every TELA application
Pre-Development
- Plan file structure (< 18KB per file)
- Identify modules needed
- Design XSWD-only data access
- Plan caching strategy
During Development
- Monitor sizes:
wc -c *.js *.css *.html - Test with real DERO daemon
- Validate XSWD integration
- Optimize for < 2s load time
Pre-Deployment
- All files < 18KB verified
- Test compression if 15-18KB
- Validate with
tela-cli serve local ./project - No external dependencies
Post-Deployment
- Test deployed functionality
- Monitor performance
- Gather user feedback
Related Documentation
- First App Tutorial - Step-by-step tutorial for beginners
- Basic App Template - Complete starter application
- XSWD Advanced - Production XSWD library
- Advanced Features - DocShards and compression
- TELA-CLI - Development tools
- JavaScript Guidelines - Proven code patterns
- XSWD Protocol - Wallet integration