Skip to content

Laravel: document compiling views before deploying - #2200

Open
mnapoli wants to merge 1 commit into
masterfrom
laravel-precompiled-views
Open

mnapoli wants to merge 1 commit into
masterfrom
laravel-precompiled-views

Conversation

@mnapoli

@mnapoli mnapoli commented Oct 7, 2026

Copy link
Copy Markdown
Member

Documents compiling Blade views before deploying a Laravel application (php artisan view:cache), in a new "Compiling views before deploying" section of the Laravel getting started page. Without it, each new Lambda instance compiles the views again on its first requests.

It relies on brefphp/laravel-bridge#217, which makes the bridge read the compiled views from the package. Before that release, following these docs changes nothing: the views keep compiling in /tmp, as today.

  • Zip deployments: enable view.relative_hash (Laravel 9 and later, so every Laravel version the bridge supports), because compiled file names depend on the absolute path of each view. Run view:cache before every deployment, and add storage/framework/views/*.php to the serverless.yml patterns.
  • Container images: run view:cache in the Dockerfile. The application is at /var/task there, so relative_hash isn't needed.
  • Routes and events can be cached too. php artisan optimize is still discouraged because it caches the configuration.

Both recipes were followed literally on AWS Lambda, with the bridge from brefphp/laravel-bridge#217 and a Laravel 13 application, FPM and Octane: the zip compiled on macOS, the container image built from the documented Dockerfile. On both:

  • every page works, and the logs are clean;
  • the precompiled views are read from /var/task/storage/framework/views, despite the 1980 file dates in the zip;
  • views rendered at runtime (Blade::render(), inline components) still compile in /tmp.

Laravel compiles Blade views on the first requests of every new Lambda instance, in /tmp.
`php artisan view:cache` before deploying skips that, now that laravel-bridge reads compiled views
from the package (brefphp/laravel-bridge#217):

- zip: `relative_hash` in config/view.php (Laravel 9+, every supported version) so that the
  compiled file names match on Lambda, and `storage/framework/views/*.php` added to the package,
- container images: `view:cache` in the Dockerfile, where the application is in /var/task.

Validated on Lambda (zip compiled on macOS with relative_hash, image built with the Dockerfile
above): compiled views read from /var/task, `Blade::render()` and inline components still compile
in /tmp. Without the laravel-bridge fix, the compiled views are ignored and nothing breaks.

Claude-Session: https://claude.ai/code/session_01Gw1bKZVqSMqFbcwXuPvUDL

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant