All Projects β†’ sergei-zelinsky β†’ react-critical-css

sergei-zelinsky / react-critical-css

Licence: other
Extracts your critical CSS.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-critical-css

nextjs-ssr-isr-cdk-aws
πŸ¦„ β€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€ŽNext.js webapp using Server Side Rendering (SSR) and Incremental Static Regeneration (ISR) deployed with Serverless Nextjs CDK construct on AWS using CloudFront and Lambda@Edge
Stars: ✭ 78 (+333.33%)
Mutual labels:  server-side-rendering
ves
Vue SSR(Server Side Render) Web Framework for Egg
Stars: ✭ 23 (+27.78%)
Mutual labels:  server-side-rendering
fractal-component
A javascript library that can help you to encapsulate decoupled UI component easily
Stars: ✭ 13 (-27.78%)
Mutual labels:  server-side-rendering
FlexDotnetCMS
A powerful, flexible, decoupled and easy to use and Fully Featured ASP .NET CMS, it can also be used as a Headless CMS
Stars: ✭ 45 (+150%)
Mutual labels:  server-side-rendering
magento-2-gulp
Gulp for Magento 2. It works with core Magento styles (less) and structure. Uses default theme configs from dev/tools/grunt/configs/local-themes.js.
Stars: ✭ 37 (+105.56%)
Mutual labels:  critical-css
universal
A counterpart to common package to be used with Angular Universal
Stars: ✭ 115 (+538.89%)
Mutual labels:  server-side-rendering
Beidou
🌌 Isomorphic framework for server-rendered React apps
Stars: ✭ 2,726 (+15044.44%)
Mutual labels:  server-side-rendering
boldr
React based CMF / blogging engine using Redux, Postgres, Node, and more...
Stars: ✭ 78 (+333.33%)
Mutual labels:  server-side-rendering
ultimate-hot-boilerplate
πŸš€ node-react universal app boilerplate with everything on hot reload, SSR, GraphQL, Flow included
Stars: ✭ 35 (+94.44%)
Mutual labels:  server-side-rendering
md-svg-vue
Material design icons by Google for Vue.js & Nuxt.js (server side support & inline svg with path)
Stars: ✭ 14 (-22.22%)
Mutual labels:  server-side-rendering
core
Server side rendering with The Elm Architecture in Deno
Stars: ✭ 16 (-11.11%)
Mutual labels:  server-side-rendering
numvalidate
Phone number validation REST API
Stars: ✭ 54 (+200%)
Mutual labels:  server-side-rendering
prism
(No longer in development). Experimental compiler for building isomorphic web applications with web components.
Stars: ✭ 106 (+488.89%)
Mutual labels:  server-side-rendering
vitext
The Next.js like React framework for better User & Developer experience!
Stars: ✭ 376 (+1988.89%)
Mutual labels:  server-side-rendering
angular-httpclient
Angular 15 Example HttpClient
Stars: ✭ 21 (+16.67%)
Mutual labels:  server-side-rendering
Live
Live views and components for golang
Stars: ✭ 251 (+1294.44%)
Mutual labels:  server-side-rendering
docsify-ssr-demo
NOTICE: This repo is outdated and SSR is work-in-progress.
Stars: ✭ 61 (+238.89%)
Mutual labels:  server-side-rendering
nars
Server rendered React Native
Stars: ✭ 85 (+372.22%)
Mutual labels:  server-side-rendering
rsp
A server-state reactive Java web framework for building real-time user interfaces and UI components.
Stars: ✭ 35 (+94.44%)
Mutual labels:  server-side-rendering
universal-react-relay-starter-kit
A starter kit for React in combination with Relay including a GraphQL server, server side rendering, code splitting, i18n, SEO.
Stars: ✭ 14 (-22.22%)
Mutual labels:  server-side-rendering

react-critical-css

Extracts your critical CSS.

Build Status npm npm npm GitHub stars

Installation

npm install react-critical-css

or

yarn add react-critical-css

Usage

// ...
import {renderToString} from 'react-dom/server';
import {CriticalCSSProvider, StyleRegistry} from 'react-critical-css'; // <-

// ...

const styleRegistry = new StyleRegistry(); // create new style registry

const appString = renderToString(
    <CriticalCSSProvider registry={styleRegistry}> // <- wrap your App component with CriticalCSSProvider and pass styleRegistry to it
      <App/>
    </CriticalCSSProvider>
);

const criticalCSS = styleRegistry.getCriticalCSS(); // <- extract collected critical CSS

App component example:

import React, {Component} from 'react';
import {withStyles} from 'react-critical-css'; // import 'withStyles'
import s from './index.css'; // import your styles, `s` should contain a string with style rules (see example webpack config below)

class App extends Component {
  // ...
  
  render(){
    return (
      <div>App component example</div>
    );
  }
}

// wrap App component with 'withStyles'

export default withStyles(s)(App);

Example Webpack configuration for CSS files

// ...

module.exports = {
// ...
  
  module: {
  // ...
    
    rules: [
    // ...
    
    {
        test: /\.css$/,
        loader: 'css-loader',
        // ...
      }
    ]
  }
};

API

StyleRegistry [Class]

Public API:

  • registerStyles - adds styles into internal registry
  • getCriticalCSS - returns critical stylesheets which has been registered through registerStyles previously
new StyleRegistry(<transformFn>);

Usage

import {StyleRegistry} from 'react-critical-css';

// ...

const styleRegistry = new StyleRegistry();

// ..

styleRegistry.registerStyles('body {color: red}');  // <- register stylesheets

// ...

const criticalCSS = styleRegistry.getCriticalCSS() // <- retrieve critical CSS
const styleRegistry = new StyleRegistry(style => style.replace(/\s/g, ''));
   
styleRegistry.registerStyles('body { color: red; }')

console.log(styleRegistry.getCriticalCSS())  //-> body{color: red;}
// ...

CriticalCSSProvider [React Component]

Passes context with registerStyles function through the React tree.

Props

  • registry - instance of StyleRegistry or other registry which supports the same API

withStyles [Decorator]

Returns HOC which registers passed stylesheets.

Arguments of withStyles

  • styles - string with CSS

Arguments of withStyles(styles)

  • Component - React Component

Usage

// ...
import {withStyles} from 'react-critical-css';
import s from 'path/to/css/file';

// ...

class MyComponent extends Component {
  // ...
}

export default withStyles(s)(MyComponent);

or using decorators

// ...
import {withStyles} from 'react-critical-css';
import s from 'path/to/css/file';

// ...

@withStyles(s)
class MyComponent extends Component {
  // ...
}

export default MyComponent;
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].