All Projects → spatie → Laravel Server Side Rendering

spatie / Laravel Server Side Rendering

Licence: mit
Server side rendering JavaScript in your Laravel application

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Laravel Server Side Rendering

React Router Server
Server Side Rendering library for React Router v4.
Stars: ✭ 443 (-12.45%)
Mutual labels:  ssr, server-side-rendering
React Firebase Starter
Boilerplate (seed) project for creating web apps with React.js, GraphQL.js and Relay
Stars: ✭ 4,366 (+762.85%)
Mutual labels:  ssr, server-side-rendering
Ssr Sample
A minimum sample of Server-Side-Rendering, Single-Page-Application and Progressive Web App
Stars: ✭ 285 (-43.68%)
Mutual labels:  ssr, server-side-rendering
React Snap
👻 Zero-configuration framework-agnostic static prerendering for SPAs
Stars: ✭ 4,565 (+802.17%)
Mutual labels:  ssr, server-side-rendering
Nuxt Firebase Sns Example
Nuxt v2 & Firebase(Hosting / Functions SSR / Firestore), Google Auth SNS Example.
Stars: ✭ 485 (-4.15%)
Mutual labels:  ssr, server-side-rendering
React Storefront
Build and deploy e-commerce progressive web apps (PWAs) in record time.
Stars: ✭ 275 (-45.65%)
Mutual labels:  ssr, server-side-rendering
React Coat
Structured React + Redux with Typescript and support for isomorphic rendering beautifully(SSR)
Stars: ✭ 290 (-42.69%)
Mutual labels:  ssr, server-side-rendering
jooger.me
👍 My personal website,powered by @nuxt
Stars: ✭ 39 (-92.29%)
Mutual labels:  ssr, server-side-rendering
Quasar
Quasar Framework - Build high-performance VueJS user interfaces in record time
Stars: ✭ 20,090 (+3870.36%)
Mutual labels:  ssr, server-side-rendering
Awesome Universal Rendering
Awesome resources about server side sendering (SSR), static rendering, pre-rendering, static site generators (SSG).
Stars: ✭ 308 (-39.13%)
Mutual labels:  ssr, server-side-rendering
React Head
⛑ SSR-ready Document Head tag management for React 16+
Stars: ✭ 262 (-48.22%)
Mutual labels:  ssr, server-side-rendering
Cra Universal
🌏 Create React App companion for universal app. No eject, auto SSR, zero config, full HMR, and more (inactive project)
Stars: ✭ 419 (-17.19%)
Mutual labels:  ssr, server-side-rendering
movies
Real world isomorphic application for movies search, based on Webpack 5 / Express / React 17 + Redux-Saga / Bootstrap 4.6 + CSS Modules / i18next / SSR
Stars: ✭ 20 (-96.05%)
Mutual labels:  ssr, server-side-rendering
Angular Ssr
Angular 4+ server-side rendering solution compatible with @angular/material, jQuery, and other libraries that touch the DOM (as well as providing a rich feature set!)
Stars: ✭ 283 (-44.07%)
Mutual labels:  ssr, server-side-rendering
egg-view-vue-ssr
Egg Vue Server Side Render (SSR) Plugin
Stars: ✭ 90 (-82.21%)
Mutual labels:  ssr, server-side-rendering
React Loadable
⏳ A higher order component for loading components with promises.
Stars: ✭ 16,238 (+3109.09%)
Mutual labels:  ssr, server-side-rendering
vue-ssr-starter
Starter kit for projects with Webpack 4, Vue 2 and SSR
Stars: ✭ 53 (-89.53%)
Mutual labels:  ssr, server-side-rendering
nx-ng-nest-universal
Nx Workspace with a seperated Nest App for Angular Universal SSR.
Stars: ✭ 32 (-93.68%)
Mutual labels:  ssr, server-side-rendering
React Storefront
React Storefront - PWA for eCommerce. 100% offline, platform agnostic, headless, Magento 2 supported. Always Open Source, Apache-2.0 license. Join us as contributor ([email protected]).
Stars: ✭ 292 (-42.29%)
Mutual labels:  ssr, server-side-rendering
After.js
Next.js-like framework for server-rendered React apps built with React Router
Stars: ✭ 4,051 (+700.59%)
Mutual labels:  ssr, server-side-rendering

Server side rendering JavaScript in your Laravel application

Latest Version on Packagist GitHub Workflow Status Total Downloads

Making server side rendering a bit less hard in Laravel.

<html>
    <head>
        <title>My server side rendered app</title>
        <script defer src="{{ mix('app-client.js') }}">
    </head>
    <body>
        {!! ssr('js/app-server.js') !!}
    </body>
</html>

This package is a Laravel bridge for the spatie/server-side-rendering library. Before getting started, dig through the readme to learn about the underlying concepts and caveats. This readme also assumes you already have some know-how about building server rendered JavaScript apps.

Vue and React example apps are available at spatie/laravel-server-side-rendering-examples if you want to see it in action.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/laravel-server-side-rendering

The service provider and Ssr alias will be automatically registered.

You can optionally publish the config file if you want to tweak things.

php artisan vendor:publish --provider="Spatie\Ssr\SsrServiceProvider" --tag="config"

Usage

Prerequisites

First you'll need to pick an engine to execute your scripts. The server-side-rendering library ships with V8 and Node engines. By default, the package is configured to use node, since you probably already have that installed on your system.

Set up the NODE_PATH environment variable in your .env file to get started:

NODE_PATH=/path/to/my/node

You'll also need to ensure that a storage/app/ssr folder exists, or change the ssr.node.temp_path config value to something else.

If you'd rather use the V8 engine, you can skip the previous two steps. You'll need to have the v8js extension installed though.

Configuration

Besides the above, no configuration's required. If you need to tweak things anyway, the config file is well documented.

Setting up your scripts

You'll need to build two scripts: a server script and a client script. Refer to your frontend-framework-of-choice's documentation on how to build those.

mix.js('resources/assets/js/app-client.js', 'public/js')
   .js('resources/assets/js/app-server.js', 'public/js');

The server script should be passed to the ssr function, the client script should be loaded manually. The package assumes you're using Laravel Mix, and will resolve the path for you. You can opt out of this behaviour by setting mix to false in the config file.

{!! ssr('js/app-server.js') !!}
<script src="{{ mix('js/app-client.js') }}">

Your server script should call a dispatch function to send the rendered html back to the view. Here's a quick example of a set of Vue scripts for a server-rendered app. Read the spatie/server-side-rendering readme for a full explanation of how everything's tied together.

// resources/assets/js/app.js

import Vue from 'vue';
import App from './components/App';

export default new Vue({
    render: h => h(App),
});
// resources/assets/js/app-client.js

import app from './app';

app.$mount('#app');
// resources/assets/js/app-server.js

import app from './app';
import renderVueComponentToString from 'vue-server-renderer/basic';

renderVueComponentToString(app, (err, html) => {
    if (err) {
        throw new Error(err);
    }

    dispatch(html);
});

Rendering an app in your view

The package exposes an ssr helper to render your app.

<html>
    <head>
        <title>My server side rendered app</title>
        <script defer src="{{ mix('app-client.js') }}">
    </head>
    <body>
        {!! ssr('js/app-server.js')->render() !!}
    </body>
</html>

A facade is available too.

<html>
    <head>
        <title>My server side rendered app</title>
        <script defer src="{{ mix('app-client.js') }}">
    </head>
    <body>
        {!! Ssr::entry('js/app-server.js')->render() !!}
    </body>
</html>

Rendering options can be chained after the function or facade call.

<html>
    <head>
        <title>My server side rendered app</title>
        <script defer src="{{ mix('app-client.js') }}">
    </head>
    <body>
        {!! ssr('js/app-server.js')->context('user', $user)->render() !!}
    </body>
</html>

Available options are documented at spatie/server-side-rendering.

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].