Git Product home page Git Product logo

critically's Introduction

Critically

Tiny performant library for extracting the critical CSS.

Compared to critical this library:

  • Is so much smaller, at about 2kb in size. critical instead needs to download a whole browser.
  • It works in the browser too, which is useful if you need to store the previous state of the app or a skeleton of it.
  • Will output slightly larger strings, as only simple minification techniques are performed.
  • Is much faster.

Install

npm install --save critically

API

This library provides the following interface:

type Options = {
  document?: Document, // The document from which to extract the critical CSS
  html?: string, // The HTML string from which to extract the critical CSS
  minify?: boolean, // Whether to enable minification or not
  transform?: ( doc: Document ) => Document | void // A function that will be run before extracting the critical CSS, useful for removing unneeded elements from the document
};

type Result = {
  clone: Document, // The cloned document object
  html: string, // Full HTML with the critical CSS embedded in it
  css: string // Only the critical CSS
};

async function critically ( options: Options ): Promise<Result>;

You need to provide either an HTML string or a document object. The document will be cloned, so you can modify it safely via the transform function.

Usage

import critically from 'critically';

const {clone, html, css} = await critically ({ document });

License

MIT © Fabio Spampinato

critically's People

Contributors

fabiospampinato avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

panjiang

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.