{"id":16193276,"url":"https://github.com/koriym/koriym.baracoa","last_synced_at":"2025-08-31T05:39:57.334Z","repository":{"id":57008565,"uuid":"80492001","full_name":"koriym/Koriym.Baracoa","owner":"koriym","description":"A JavaScript server side rendering interface for PHP","archived":false,"fork":false,"pushed_at":"2017-05-10T23:07:17.000Z","size":812,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"1.x","last_synced_at":"2025-05-22T07:49:49.069Z","etag":null,"topics":["html","javascript","performance-boost","php","redux","snapshot","ssr","template-engine","v8js"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koriym.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-31T04:47:18.000Z","updated_at":"2020-03-14T02:02:35.000Z","dependencies_parsed_at":"2022-08-21T13:10:12.223Z","dependency_job_id":null,"html_url":"https://github.com/koriym/Koriym.Baracoa","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/koriym/Koriym.Baracoa","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koriym%2FKoriym.Baracoa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koriym%2FKoriym.Baracoa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koriym%2FKoriym.Baracoa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koriym%2FKoriym.Baracoa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koriym","download_url":"https://codeload.github.com/koriym/Koriym.Baracoa/tar.gz/refs/heads/1.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koriym%2FKoriym.Baracoa/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272943317,"owners_count":25019509,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-31T02:00:09.071Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html","javascript","performance-boost","php","redux","snapshot","ssr","template-engine","v8js"],"created_at":"2024-10-10T08:14:29.405Z","updated_at":"2025-08-31T05:39:57.289Z","avatar_url":"https://github.com/koriym.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Baracoa\n\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/koriym/Koriym.Baracoa/badges/quality-score.png?b=1.x)](https://scrutinizer-ci.com/g/koriym/Koriym.Baracoa/?branch=1.x)\n[![Code Coverage](https://scrutinizer-ci.com/g/koriym/Koriym.Baracoa/badges/coverage.png?b=1.x)](https://scrutinizer-ci.com/g/koriym/Koriym.Baracoa/?branch=1.x)\n[![Build Status](https://travis-ci.org/koriym/Koriym.Baracoa.svg?branch=1.x)](https://travis-ci.org/koriym/Koriym.Baracoa)\n\n\n## A JavaScript server side rendering interface\n\n**Bracoa** provides a simple interface for JavaScript server side rendering in PHP.\n\n## Prerequisites\n\n * php7.1\n * [V8Js](http://php.net/v8js) \n\n## Installation\n   \n```\ncomposer require koriym/baracoa\n```\n\n## Basic\n\nIn a JS renderer application, implement `render` function which takes parameter(s) and return html string. \n\n```javascript\nconst render = state =\u003e (\n  `Hello ${state.name}`\n)\n```\n\nCall the `render()` method with JS app name and values to assign to redner.\n\n```php\n$baracoa = new Baracoa($jsDir, new ExceptionHandler());\n$html = $baracoa-\u003erender('min', ['name' =\u003e 'World']);\necho $html; // Hello World\n```\n\nIn this example, you need to place `min.bundle.js` JS file in `$jsDir ` directory.\nEvery page needs own JS view application which is bundled single file by bundler tool like [webpack](https://webpack.github.io/).\n\n\nTypical entry file is like following code.\n\n```\nimport render from './render';\nglobal.render = render;\n```\n\n\nIn next section we see the example of Redux with React applicaiton example.\n\n\n## Redux React\n\n### The Server Side\n\nInject an initial component HTML and initial state into a template to be rendered on the client side.\nTo pass along the state, we add a `\u003cscript\u003e` tag that will attach `preloadedState` to `window.__PRELOADED_STATE__`.\nThe preloadedState will then be available on the client side by accessing `window.__PRELOADED_STATE__`.\n\nWe also include our bundle file for the client-side application via a `\u003cscript\u003e` tag.\nThis is whatever output your bundling tool provides for your client entry point. \n\n\n### render.js\n\n```javascript\nimport React from 'react';\nimport { renderToString } from 'react-dom/server';\nimport { Provider } from 'react-redux';\nimport escape from 'escape-html';\nimport serialize from 'serialize-javascript';\nimport App from '../containers/App';\nimport configureStore from '../store/configureStore';\n\nconst render = (preloadedState, metas) =\u003e {\n  const store = configureStore(preloadedState);\n  const root = renderToString(\n    \u003cProvider store={store}\u003e\n      \u003cApp /\u003e\n    \u003c/Provider\u003e,\n  );\n  return `\u003c!doctype html\u003e\n    \u003chtml\u003e\n      \u003chead\u003e\n        \u003ctitle\u003e${escape(metas.title)}\u003c/title\u003e\n      \u003c/head\u003e\n      \u003cbody\u003e\n        \u003cdiv id=\"root\"\u003e${root}\u003c/div\u003e\n        \u003cscript\u003e\n          window.__PRELOADED_STATE__ = ${serialize(preloadedState)}\n        \u003c/script\u003e\n        \u003cscript src=\"/build/index.bundle.js\"\u003e\u003c/script\u003e\n      \u003c/body\u003e\n    \u003c/html\u003e\n`;\n};\n\nexport default render;\n```\n\n`render()` method can pass second parameter as SSR meta data which is only available in server side rendering. Typically this value is used in `\u003cheader\u003e` such as for OGP.\n\n```php\n$meta = ['title =\u003e 'awesome page'];\n$html = $baracoa-\u003erender('min', ['name' =\u003e 'World'], $meta);\n```\n\n### The Client Side\n\n\nWe need to do is grab the initial state from `window.__PRELOADED_STATE__` which is rendered in server side, and pass it to our `createStore()` function as the initial state.\n\n```javascript\nimport React from 'react';\nimport { render } from 'react-dom';\nimport { Provider } from 'react-redux';\nimport configureStore from '../store/configureStore';\nimport App from '../containers/App';\n\nconst preloadedState = window.__PRELOADED_STATE__;\nconst store = configureStore(preloadedState);\n\nrender(\n  \u003cProvider store={store}\u003e\n    \u003cApp /\u003e\n  \u003c/Provider\u003e,\n  document.getElementById('root'),\n);\n```\n\n## Performance boost \n\n```php\n$cache = new FilesystemCache() // PSR-16\n$baracoa = new CacheBaracoa($appBundleJsPath, new ExceptionHandler(), $cache);\n```\nAn *external* \"snapshot\" is saved to increase performance in each app with `CacheBaracoa`.\nHighly recommended in production site.\nConsider *internal* snapshot for more performance.\n\nSee more detail in this blog post.\n\n* [20x performance boost with V8Js snapshots](http://stesie.github.io/2016/02/snapshot-performance)\n\n## Run demo\n\n### min\n\n```\ngit clone git@github.com:koriym/Koriym.Baracoa.git\ncd Koriym.Baracoa\ncomposer install\ncd docs/example/min\nphp index.php\n// HelloWorld\n```\n\n### handlebar\n\n```\ncd docs/example/handlesbar\nyarn install\nyarn run build\nphp public/index.php\n\n// \u003c!doctype html\u003e\n// ...\n```\n\n### redux react\n\n```\ncd docs/example/redux\nyarn install\nyarn run build\nyarn start\n```\n\n## Install V8Js\n\n### OSX\n\n```\nbrew update\nbrew install homebrew/php/php71-v8js\n```\n\nedit `php.ini` or add 'V8Js.ini'\n\n```\nextension=\"/usr/local/opt/php71-v8js/v8js.so\"\n```\n\n## JS UI Application Skeleton\n\n[UiSkeleton](https://github.com/koriym/Koriym.JsUiSkeleton) is a Javascript UI application skeleton with  hot module loader, browsersync, test, lint and more for development.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoriym%2Fkoriym.baracoa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoriym%2Fkoriym.baracoa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoriym%2Fkoriym.baracoa/lists"}