Download the PHP package bear/ssr-module without Composer
On this page you can find all versions of the php package bear/ssr-module. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bear/ssr-module
More information about bear/ssr-module
Files in bear/ssr-module
Informations about the package ssr-module
BEAR.SsrModule
JavaScript view layer for BEAR.Sunday
This module enables you to write views in JavaScript while keeping your application logic in PHP. The JavaScript templates are executed server-side (SSR) for initial rendering and can hydrate on the client for interactivity.
When to Use This Module
- You want to write views in JavaScript (React, Vue, etc.) within a PHP application
- You prefer to keep server-side application logic in BEAR.Sunday while using JavaScript for UI
- You need both server-side rendering and client-side hydration with the same view code
Prerequisites
- PHP 8.2+
- Node.js (for SSR execution)
- V8Js (Optional - for embedded execution without process overhead)
Install
Composer Install
Module Install
Place your {app}.bundle.js file in the $buildDir directory. This JS is used for server side rendering (SSR) only.
[Ssr] Attribute
Basic
Add the #[Ssr] attribute to methods where you want SSR. Set the JS application name with app.
JS Render Application
Here is a minimalistic JS application. Export a render function.
Use koriym/js-ui-skeleton to create a JavaScript UI application.
State and Metas
In SSR applications, you may need two kinds of data:
state: Public data sent to the client (included in HTML)metas: Server-side only data
Separate them using the state and metas parameters in the #[Ssr] attribute:
render.js:
Cache Modules
For production, use cache modules to improve performance:
APCu Cache
Custom Cache
JavaScript Runtime
This module uses koriym/baracoa for JavaScript execution, which supports two runtimes:
| Runtime | Pros | Cons |
|---|---|---|
| Node.js (default) | No PHP extension required, easy deployment | Process spawn overhead per render |
| V8Js | Embedded execution, no process overhead | Requires PHP extension installation |
Node.js is used automatically when V8Js is not available.
Performance Note
When using event-driven caching with TTL=0 (cache invalidated by events rather than time), the Node.js process overhead becomes negligible. The rendered HTML is cached indefinitely and invalidated only when the underlying data changes, so JavaScript execution occurs only on cache misses.
All versions of ssr-module with dependencies
bear/resource Version ^1.15
koriym/baracoa Version ^1.0
ray/aop Version ^2.14
