Giter VIP home page Giter VIP logo

embryo-ssr's Introduction

Embryo SSR (Server Side Rendering)

Server Side Rendering Javascript in PHP application with V8Js.

Requirements

Installation

Using Composer:

$ composer require davidecesarano/embryo-ssr

Usage

You can use SSR if you want rendering a "snapshot" of our app. The JavaScript frameworks (like Vuejs or React) build client-side applications that manipulate DOM in the browser as output.

With Embryo SSR is possible to render the components into HTML strings on the server, send them directly to the browser, and finally "hydrate" the static markup into a fully interactive app on the client.

use Embryo\ServerSideRendering\SSR;

$v8js = new \V8Js;
$ssr = new SSR($v8js);

echo $ssr
    ->env([
        'NODE_ENV' => 'production',
        'VUE_ENV' => 'server'
    ])
    ->context([
        'user' => [
            'name' => 'Davide'
        ]
    ])
    ->entry('path/to/js/entry-server.js')
    ->render();

Example

You may quickly test using the built-in PHP server going to http://localhost:8000.

$ cd example
$ php -S localhost:8000

Options

enabled(bool $enabled = true): self

Enables or disables server side rendering. When disabled, the client script and the fallback html will be rendered instead.

env(array $env): self

ENV variables are placed in process.env when the server script is executed.

entry($entry): self

The path to your server script. Must be an arrary for multiple files.

context(array $context): self

Context is passed to the server script in the context variable.

script(string $script): self

Writes a javascript script. For example: var a = "My Var".

fallback(string $fallback): self

Sets the fallback html for when server side rendering is disabled. For example: <div id="app"></div>.

embryo-ssr's People

Contributors

davidecesarano avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.