Giter Site home page Giter Site logo

t09tanaka / next-critical Goto Github PK

View Code? Open in Web Editor NEW
14.0 1.0 1.0 20 KB

Next Critical is a plug in that improve your web site speed with Critical CSS.

License: MIT License

TypeScript 95.73% CSS 0.47% JavaScript 3.80%
react server-rendering universal node components browser nextjs

next-critical's Introduction

Next Critical⚡

Next Critical is a plug in that improve your web site speed with Critical CSS.

How to use

Install:

npm i -S next-critical

Create custom head component with your Critical CSS in _document.js.

import Document, { Html, Head, Main, NextScript } from 'next/document'
import CustomHead from 'next-critical'
import { readFileSync } from 'fs'
import * as React from 'react'

let styleSheetContent: string = ''

export default class MyDocument extends Document {
  // @ts-ignore
  static async getInitialProps(ctx) {
    const initialProps = await Document.getInitialProps(ctx)

    // Your critical css file
    const filePath = `./src/styles/critical.css`
    styleSheetContent = readFileSync(filePath, 'utf8')

    return { ...initialProps }
  }

  render() {
    const CriticalCssHead = CustomHead(Head, styleSheetContent)

    return (
      <Html>
        <CriticalCssHead />
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    )
  }
}

Related links

zeit/next.js - Framework for server-rendered React applications

next-critical's People

Contributors

t09tanaka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

st7art22

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.