Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-server-renderer

Package Overview
Dependencies
Maintainers
2
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-server-renderer

server renderer for Vue 2.0

  • 2.7.16
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
422K
increased by20.83%
Maintainers
2
Weekly downloads
 
Created

What is vue-server-renderer?

The vue-server-renderer package is used for server-side rendering (SSR) of Vue.js applications. It allows you to render Vue components on the server and send the HTML to the client, which can improve performance and SEO.

What are vue-server-renderer's main functionalities?

Basic Server-Side Rendering

This feature allows you to render a Vue component to a string on the server. The rendered HTML can then be sent to the client.

const Vue = require('vue');
const renderer = require('vue-server-renderer').createRenderer();

const app = new Vue({
  template: '<div>Hello World</div>'
});

renderer.renderToString(app, (err, html) => {
  if (err) throw err;
  console.log(html); // <div data-server-rendered="true">Hello World</div>
});

Using a Render Context

This feature allows you to pass a context object to the renderer, which can be used to inject additional data into the rendered HTML.

const Vue = require('vue');
const renderer = require('vue-server-renderer').createRenderer();

const app = new Vue({
  template: '<div>{{ message }}</div>',
  data: {
    message: 'Hello World'
  }
});

const context = {
  title: 'My Vue App',
  meta: '<meta charset="utf-8">'
};

renderer.renderToString(app, context, (err, html) => {
  if (err) throw err;
  console.log(html); // <div data-server-rendered="true">Hello World</div>
  console.log(context); // { title: 'My Vue App', meta: '<meta charset="utf-8">' }
});

Streaming Server-Side Rendering

This feature allows you to render a Vue component to a stream, which can be useful for large applications where you want to start sending HTML to the client as soon as possible.

const Vue = require('vue');
const renderer = require('vue-server-renderer').createRenderer();

const app = new Vue({
  template: '<div>Hello World</div>'
});

const stream = renderer.renderToStream(app);

stream.on('data', chunk => {
  process.stdout.write(chunk);
});

stream.on('end', () => {
  console.log('Stream ended');
});

Other packages similar to vue-server-renderer

Keywords

FAQs

Package last updated on 24 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc