Spark System
Azu's Spark system provides client-side JavaScript for real-time DOM updates and WebSocket communication. It enables seamless real-time interactions between server-side components and client-side JavaScript.
Overview
The Spark system provides:
Automatic WebSocket management for real-time connections
DOM manipulation with server-sent updates
Event handling for client-server communication
Component synchronization between server and client
Error handling and reconnection logic
Architecture
Basic Setup
Including Spark
<!-- Include Spark in your HTML template -->
<!DOCTYPE html>
<html>
<head>
<title>Azu Application</title>
</head>
<body>
<!-- Your content here -->
<!-- Include Spark JavaScript -->
<script src="/js/azu-spark.js"></script>
<script>
// Initialize Spark
Spark.init({
host: window.location.hostname,
port: 3000,
secure: window.location.protocol === "https:",
});
</script>
</body>
</html>Component Integration
Spark API
Core Methods
Event Handling
DOM Manipulation
WebSocket Management
Connection Handling
Error Handling
Component Communication
Server to Client
Client to Server
Advanced Features
Component State Management
Batch Updates
Custom Event Handlers
Performance Optimization
Debounced Events
Throttled Updates
Connection Pooling
Error Recovery
Automatic Reconnection
Message Queuing
Debugging
Debug Mode
Performance Monitoring
Best Practices
1. Event Management
Use descriptive event names
Validate event data on both client and server
Clean up event listeners when components are destroyed
Use namespaced events for complex applications
2. DOM Updates
Batch multiple DOM updates when possible
Use specific element IDs for updates
Avoid updating large DOM trees frequently
Use CSS classes for state changes
3. Error Handling
Always handle connection errors
Implement proper reconnection logic
Provide user feedback for connection issues
Log errors for debugging
4. Performance
Debounce frequent events
Throttle DOM updates
Use connection pooling for multiple components
Monitor performance metrics
Next Steps
WebSocket Channels - Server-side WebSocket handling
Live Components - Real-time UI components
Spark Examples - Working examples
Ready to add real-time interactivity? Start with the basic Spark setup above, then explore Live Components for complete real-time solutions.
Last updated
Was this helpful?
