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

spinner

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"
end

Advanced Configuration

File Types and Reload Strategies

Template Files (.html)

Template files trigger template-specific reloads:

When this file changes:

  1. Template is recompiled with new content

  2. Component state is preserved

  3. Only affected components are updated

  4. No full page reload required

Crystal Files (.cr)

Crystal source files trigger component reloads:

When this file changes:

  1. Component is recompiled

  2. Component instances are updated

  3. DOM is patched with changes

  4. State is preserved where possible

Static Files (.css, .js)

Static files trigger browser refresh:

When this file changes:

  1. Browser refreshes the page

  2. New CSS/JS is loaded

  3. Full page state is reset

Development Workflow

Starting Development Server

Development Process

  1. Make changes to templates, components, or static files

  2. Save the file - hot reloader detects the change

  3. Automatic update - browser updates without manual refresh

  4. 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/ directory

  • Organize components in components/ directory

  • Use 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


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?