Giter Club home page Giter Club logo

critical-css-server's Introduction

Eliminate render-blocking CSS in above-the-fold content

If you've run Google Pagespeed Insights on your web app, you might have seen this message:

Eliminate render-blocking JavaScript and CSS in above-the-fold content

Your page has blocking CSS resources. This causes a delay in rendering your page. None of the above-the-fold content on your page could be rendered without waiting for the following resources to load. Try to defer or asynchronously load blocking resources, or inline the critical portions of those resources directly in the HTML.

This server generates the critical path CSS for you. It is designed to sit alongside your production app, and prepare the critical CSS asynchronously.

Builds can be started after each deploy, and a few seconds later, you'll be able to defer or asynchronously load blocking resources, and inline the critical portions for your page.

Install

npm install critical-path-server

Usage

Start the server

npm start
> Listening on port: 8080

Send a request with details about the page you want cached

The first request returns immediately, and starts generating the CSS in the background:

curl -H "Content-Type: application/json" -X POST -d '{ "page": {"key":"unique-key","url":"http://www.example.com/","css":"https://www.example.com/style.css"}}' localhost:5000/api/v1/css
> Accepted

Eventually...

curl -H "Content-Type: application/json" -X POST -d '{ "page": {"key":"unique-key","url":"http://www.example.com/","css":"https://www.example.com/style.css"}}' localhost:5000/api/v1/css
> .your-critical-css {}

Ruby on Rails

Use the Ruby on Rails client to manage rewriting and lazy-loading your other CSS assets, once the critical path has been compiled and is available.

RailsCriticalCssServer

Docker

This repo is setup with docker. You can get it up and running with the following commands.

docker build -t critical-css-server .
docker-compose up critical-css

critical-css-server's People

Contributors

hasghari avatar josh-m-sharpe avatar wheeyls avatar

Stargazers

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

Watchers

 avatar  avatar

critical-css-server's Issues

following usage instructions results in error

I can't seem to get this running locally - errors below. Is it possible the installation/usage sections are out of date?

More broadly - how are you hosting this for production? On heroku maybe? A section in the README about how to set that up would be much appreciated.

Thanks!

(12:05 PM) jsharpe@mbp:~/ys-critical-path-server npm install critical-path-server
npm WARN deprecated [email protected]: This project has moved to critical-css-server
npm WARN deprecated [email protected]: Use uuid module instead

> [email protected] install /Users/jsharpe/ys-critical-path-server/node_modules/phantomjs-prebuilt
> node install.js

PhantomJS not found on PATH
Download already available at /var/folders/8d/psl4_tyd38b7c_y2qwyxwdz80000gn/T/phantomjs/phantomjs-2.1.1-macosx.zip
Verified checksum of previously downloaded file
Extracting zip contents
Removing /Users/jsharpe/ys-critical-path-server/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder /var/folders/8d/psl4_tyd38b7c_y2qwyxwdz80000gn/T/phantomjs/phantomjs-2.1.1-macosx.zip-extract-1502467534667/phantomjs-2.1.1-macosx -> /Users/jsharpe/ys-critical-path-server/node_modules/phantomjs-prebuilt/lib/phantom
Writing location.js file
Done. Phantomjs binary available at /Users/jsharpe/ys-critical-path-server/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs
npm WARN saveError ENOENT: no such file or directory, open '/Users/jsharpe/ys-critical-path-server/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/Users/jsharpe/ys-critical-path-server/package.json'
npm WARN ys-critical-path-server No description
npm WARN ys-critical-path-server No repository field.
npm WARN ys-critical-path-server No README data
npm WARN ys-critical-path-server No license field.

+ [email protected]
added 213 packages in 13.279s
(12:05 PM) jsharpe@mbp:~/ys-critical-path-server npm start
npm ERR! path /Users/jsharpe/ys-critical-path-server/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/Users/jsharpe/ys-critical-path-server/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jsharpe/.npm/_logs/2017-08-11T16_05_38_097Z-debug.log

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.