Enable Hot Reload

This guide shows you how to enable hot reload for templates during development.

Enable Hot Reload

Configure hot reload in your application:

Azu.configure do |config|
  # Enable in development
  if ENV.fetch("AZU_ENV", "development") == "development"
    config.template_hot_reload = true
  end
end

How It Works

When hot reload is enabled:

  1. Templates are not cached between requests

  2. Changes to template files are reflected immediately

  3. No server restart required

Without hot reload:

  • Templates are compiled and cached at startup

  • Better performance but requires restart for changes

Development vs Production

File Watching

For automatic browser refresh, use a file watcher:

Using Watchexec

Using entr

Browser Auto-Refresh

Add LiveReload support:

Server-Sent Events Approach

Client-side script:

Using LiveReload.js

Run LiveReload server:

Custom Watch Script

Create a development script:

Sentry for Crystal

Use Sentry for file watching:

Run with Sentry:

Performance Considerations

Hot reload has overhead:

  • Template parsing on every request

  • File system access for each template

  • Not suitable for production

Troubleshooting

Changes Not Reflecting

  1. Check file path matches template lookup

  2. Ensure hot reload is enabled

  3. Check for template caching in your code

Slow Performance

  1. Reduce number of watched files

  2. Use more specific watch patterns

  3. Consider using browser caching for assets

See Also

Last updated

Was this helpful?