GithubHelp home page GithubHelp logo

daertommy / elacca Goto Github PK

View Code? Open in Web Editor NEW

This project forked from remorses/elacca

0.0 0.0 0.0 357 KB

Disable SSR for specific pages in Next.js, vastly decreasing code loaded in the server

JavaScript 3.65% TypeScript 96.25% CSS 0.10%

elacca's Introduction




elacca

Improve your Next.js app cold start time by 10x (maybe, still experimenting)



Reduce your Next.js app server code size by disabling SSR for specific pages.

Why

  • Improve cold start times in serverless environments
  • Improve rendering times, since the server no longer needs to render the page to html
  • Improve memory usage on the server (your pages no longer load React components code in memory)
  • Makes edge Vercel deploy possible if your current bundle size is more than 2Mb compressed
  • When SSR is not very useful, for example when making dashboards, where SEO is not important

Install

npm i -D elacca

Usage

Full application example in the example-app folder.

// next.config.js
const { withElacca } = require('elacca')

/** @type {import('next').NextConfig} */
const config = {}

const elacca = withElacca({})

const nextConfig = elacca(config) // notice the double invocation

module.exports = nextConfig

When using the pages directory, you can add a directive to disable SSR for a specific page:

// pages/index.js
'skip ssr'

export default function Home() {
    return <div>hello world</div>
}

How It Works

To have an intuitive understanding of how this works, you can check out how this plugin transforms pages in the example-app/elacca-outputs folder.

  • When a page has a "skip ssr" directive, this plugin will transform the page code so that
  • On the server the page renders a component that returns null
  • On the client the page renders null until the component mounts, removing the need to hydrate the page
  • This is implemented as a babel plugin that only runs on pages files, so your build should remain fast (all other files are not parsed by babel, usually the code inside the pages folder is not much)

Why The Name

From the Dune wiki:

The Elacca drug is a narcotic that was formed by the burning of Elacca Wood of the planet Ecaz. Its main characteristic when administered was that it would eliminate the user's will for self-preservation

elacca's People

Contributors

remorses 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.