spatie/mjml-sidecar
Compile MJML email templates to responsive HTML via AWS Lambda using Sidecar. A companion to spatie/mjml-php: deploy the provided MjmlFunction, then call Mjml::new()->sidecar()->toHtml($mjml) to render HTML without local Node/MJML.
spatie/mjml-sidecar) replaces the traditional MJML-to-HTML compilation (via mjml-php) with Sidecar, a modern, WASM-based compiler. This is a strong fit for Laravel applications requiring email templating (e.g., Mailables, notifications) where:
Mailable classes) and Blade templating, as MJML is often used for responsive email templates.mjml-php → spatie/mjml-sidecar) with minimal code changes. Existing MJML templates (.mjml files) remain compatible.config/mjml.php (if used) to point to the new package, but no breaking changes to template syntax.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| WASM Compatibility | Sidecar requires WASM support (PHP 8.1+). Older PHP versions may fail. | Enforce PHP 8.1+ in composer.json; provide fallback for legacy systems. |
| Cold Starts | WASM initialization adds ~50–100ms latency on first request. | Pre-warm Sidecar in Laravel’s booted event (e.g., via a singleton service). |
| Template Validation | MJML syntax errors may surface differently (e.g., WASM throws vs. PHP exceptions). | Implement a pre-compile validation layer (e.g., MjmlValidator). |
| Dependency Bloat | Adds WASM binary (~1MB) to deployment. | Optimize build process (e.g., tree-shake unused MJML features). |
mjml-php in our current stack (e.g., shared hosting vs. Kubernetes)?mjml-php as a backup for unsupported environments?.mjml files with deprecated syntax that Sidecar won’t support?composer remove spatie/mjml-php
composer require spatie/mjml-sidecar
Mjml::toHtml() with MjmlSidecar::toHtml() in:
app/Mail/* classes..mjml files through Sidecar in a staging environment to catch syntax issues early.AppServiceProvider::boot():
MjmlSidecar::compile('<mjml>...</mjml>'); // Trigger WASM init early
laravel-notification-channels (e.g., Mailgun, SendGrid).spatie/laravel-activitylog for email event tracking.{{ variable }} placeholders in Blade/MJML hybrid templates render correctly.| Phase | Tasks | Tools/Metrics |
|---|---|---|
| Discovery | Audit current MJML usage; benchmark mjml-php vs. Sidecar. |
Blackfire, custom latency tests. |
| Pilot | Migrate a non-critical email service (e.g., password resets). | Error logging, open telemetry. |
| Rollout | Gradually replace mjml-php in CI/CD pipelines. |
Feature flags, canary releases. |
| Optimization | Tune WASM memory limits; cache compiled HTML templates. | Sidecar logs, Redis cache hits. |
MjmlSidecar to log compilation errors/metrics.WASM_INSTANTIATION_FAILED).mjml-php under load (per Spatie benchmarks).| Scenario | Impact | Mitigation |
|---|---|---|
| WASM Initialization Failure | Email rendering fails silently. | Fallback to mjml-php or queue retries. |
| MJML Syntax Errors | Compilation throws WASM errors. | Pre-validate templates in CI. |
| PHP < 8.1 | WASM unsupported. | Block deployment; upgrade PHP. |
| High Memory Usage | OOM kills worker processes. | Set WASM memory limits in config. |
memory.rss metrics).mjml-php calls to Sidecar.How can I help you explore Laravel packages today?