Hot Reload
Azu provides hot reloading capabilities that automatically refresh your application when templates, components, or other files change during development. This feature significantly improves development productivity by eliminating the need for manual server restarts.
Overview
Hot reloading in Azu provides:
Instant template updates when template files change
Component state preservation during updates
Automatic browser refresh for file changes
Development productivity boost with fast feedback loops
Selective reloading for different file types
Architecture
Configuration
Basic Setup
# Enable hot reloading in development
Azu::Environment.configure :development do |config|
config.hot_reload = true
config.hot_reload_port = 35729
config.hot_reload_host = "localhost"
endAdvanced Configuration
File Types and Reload Strategies
Template Files (.html)
.html)Template files trigger template-specific reloads:
When this file changes:
Template is recompiled with new content
Component state is preserved
Only affected components are updated
No full page reload required
Crystal Files (.cr)
.cr)Crystal source files trigger component reloads:
When this file changes:
Component is recompiled
Component instances are updated
DOM is patched with changes
State is preserved where possible
Static Files (.css, .js)
.css, .js)Static files trigger browser refresh:
When this file changes:
Browser refreshes the page
New CSS/JS is loaded
Full page state is reset
Development Workflow
Starting Development Server
Development Process
Make changes to templates, components, or static files
Save the file - hot reloader detects the change
Automatic update - browser updates without manual refresh
Continue development - see changes instantly
File Change Examples
Template Change
Result: Only the heading element is updated, preserving all other content and state.
Component Change
Result: Component is re-rendered with new content, preserving any component state.
CSS Change
Result: Browser refreshes to load new CSS styles.
Hot Reload Strategies
Template Reload
For template file changes:
Component Reload
For Crystal component file changes:
CSS Reload
For CSS file changes:
Browser Integration
WebSocket Connection
The hot reloader establishes a WebSocket connection with the browser:
Template Updates
Component Updates
State Preservation
Component State
Form State
Performance Optimization
Selective Watching
Debounced Updates
Troubleshooting
Common Issues
Hot Reload Not Working
Template Changes Not Reflecting
Component State Lost
Debug Mode
Best Practices
1. File Organization
Keep templates in
templates/directoryOrganize components in
components/directoryUse consistent file naming conventions
Separate concerns between files
2. State Management
Implement proper state serialization
Preserve important user input
Handle state restoration gracefully
Test state preservation during development
3. Performance
Use selective file watching
Implement debounced updates
Avoid watching unnecessary files
Monitor hot reload performance
4. Development Workflow
Use hot reloading during development
Test changes immediately
Keep browser console open for errors
Use development tools for debugging
Next Steps
Template Engine - Learn about Jinja2 templates
Markup DSL - Build components with Crystal code
Development Setup - Set up your development environment
Ready to boost your development productivity? Enable hot reloading in your development environment and experience instant feedback when making changes to templates and components.
Last updated
Was this helpful?
