Giter VIP home page Giter VIP logo

fast-vue-ssr's Introduction

Fast Vue SSR with Rust and QuickJS

An ongoing experiment using Rust, Warp and QuickJS to server-side render Vue.js applications.

use renderer::RendererPool;
#[tokio::main]
pub async fn main() -> io::Result<()> {
    let pool = Arc::new(Mutex::new(RendererPool::new(64)));
    let renderer = warp::path::full().map(move |path: FullPath| {
        let renderer = Arc::clone(&pool);
        let s = path.as_str().to_string();
        // Currently only passing path to renderer is possible
        // Full Request object is a WIP
        let result = renderer.lock().unwrap().render(s);
        result
    });
    let routes = warp::path::full()
        .and(renderer)
        .map(|_, result| reply::html(result));

So far using a thread pool and channels to communicate with the Warp route handler. The goal is to get a full Node-like IncomingMessage object available as $ssrContext.req. It already includes a /static handler and serves a code-splitted build on the client via Rollup.

Node outperforms QuickJS by a wide margin. Especially with enough cores and memory. However, QuickJS is very small and has very low memory consumption, so running it threaded in a Rust shell makes it possible to have very high throughput using very few resources in comparison.

Inspired by Xinjiang Shao's experiment.

Running

  1. Install Rust.
  2. npm install
  3. npm test

Or npm run build for generating the Rust binary.

fast-vue-ssr's People

Contributors

galvez avatar nurodev avatar dependabot[bot] 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.