2.3.3 • Published 8 months ago

penthouse v2.3.3

Weekly downloads
30,582
License
MIT
Repository
github
Last release
8 months ago

penthouse

Critical Path CSS Generator

NPM version Build Status Downloads

About

Penthouse is the original critical path css generator, helping you out to speed up page rendering for your websites. Supply your site's full CSS and the page you want to create the critical CSS for, and Penthouse will return the critical CSS needed to perfectly render the above the fold content of the page. Read more about critical path css here.

The process is automatic and the generated CSS is production ready as is. Behind the scenes Penthouse is using puppeteer to generate the critical css via the chromium:headless.

Usage

Penthouse can be used:

As a Node module

yarn add --dev penthouse

(or npm install, if not using yarn)

This will add penthouse to the list of dependencies.

Penthouse returns a promise (since version 0.11), but if you prefer you can also pass in a traditional node-style callback function as the second argument.

penthouse({
    url: 'http://google.com',       // can also use file:/// protocol for local files
    cssString: 'body { color; red }', // the original css to extract critcial css from
    // css: 'pathTo/main.css',      // path to original css file on disk

    // OPTIONAL params
    width: 1300,                    // viewport width
    height: 900,                    // viewport height
    keepLargerMediaQueries: false,  // when true, will not filter out larger media queries
    forceInclude: [ // selectors to keep
      '.keepMeEvenIfNotSeenInDom',
      /^\.regexWorksToo/
    ],
    propertiesToRemove: [
      '(.*)transition(.*)',
      'cursor',
      'pointer-events',
      '(-webkit-)?tap-highlight-color',
      '(.*)user-select'
    ],
    timeout: 30000,                 // ms; abort critical CSS generation after this timeout
    pageLoadSkipTimeout: 0,         // ms; stop waiting for page load after this timeout (for sites with broken page load event timings)
    maxEmbeddedBase64Length: 1000,  // characters; strip out inline base64 encoded resources larger than this
    userAgent: 'Penthouse Critical Path CSS Generator', // specify which user agent string when loading the page
    renderWaitTime: 100,            // ms; render wait timeout before CSS processing starts (default: 100)
    blockJSRequests: true,          // set to false to load (external) JS (default: true)
    customPageHeaders: {
      'Accept-Encoding': 'identity' // add if getting compression errors like 'Data corrupted'
    },
    strict: false,                  // set to true to throw on CSS errors
    screenshots: {
      // turned off by default
      // basePath: 'homepage', // absolute or relative; excluding file extension
      // type: 'jpeg', // jpeg or png, png default
      // quality: 20 // only applies for jpeg type
      // -> these settings will produce homepage-before.jpg and homepage-after.jpg
    },
    puppeteer: {
      getBrowser: undefined,        // A function that resolves with a puppeteer browser to use instead of launching a new browser session
    }
})
.then(criticalCss => {
    // use the critical css
    fs.writeFileSync('outfile.css', criticalCss);
})
.catch(err => {
    // handle the error
})

The Penthouse Node module can also be used in Gulp.

Online version

https://jonassebastianohlsson.com/criticalpathcssgenerator/

Troubleshooting

Enable debug logging

Logging is done via the debug module under the penthouse namespace. You can view more about the logging on their documentation.

# Basic verbose logging for all components
env DEBUG="penthouse,penthouse:*" node script.js

Not working on Linux

Install missing dependencies to get the headless Chrome to run:

sudo apt-get install libnss3

You might possibly need an even longer list of deps, depending on your dist, see this answer

Problems with generated CSS

A good first step can be to test your url + css in the hosted critical path css generator, to determine whether the problem is with the input your passing (css + url), or with your local setup: https://jonassebastianohlsson.com/criticalpathcssgenerator

Unstyled content showing when using the critical css

If you see flashes of unstyled content showing after applying your critical css then something is wrong. Below are the most commont causes and some general related advice:

Your page contains dynamic or JS injected/activated content.

Generally you have to ensure that all elements you want styled in the critical css appears (visible) in the HTML of your page (with Javascript disabled). The first render of your page, the one critical css helps make much faster, happens before JS has loaded, which is why Penthouse runs with JavaScript disabled. So if your html is essentially empty, or your real content is hidden before a loading spinner or similar you have to adress this before you can get the performance benefits of using critical css.

If your html is fine, but varies based on things such as the logged in user, third party advertising etc, then you can use the forceInclude parameter to force specific extra styles to remain in the critical css, even if Penthouse doesn’t see them on the page during critical css generation.

Early DOM content moved out of critical viewport via CSS

This problem can happen if you have an element appearing early in the DOM, but with styles applied to move outside of the critical viewport (using absolute position or transforms). Penthouse does not look at the absolute position and transform values and will just see the element as not being part of the critical viewport, and hence Penthouse will not consider it’s styles critical (so the unstyled element will show when the critical css is used). Solution: Consider whether it really should appear so early in the DOM, or use the forceInclude property to make sure the styles to "hide"/move it are left in the critical css.

Special glyphs not showing/showing incorrectly

Problems with special characters like after converting? Make sure you use the correct hexadecimal format in your CSS. You can always get this format from your browser console, by entering ''.charCodeAt(0).toString(16) (answer for this arrow glyph is 2192). When using hexadecimal format in CSS it needs to be prepended with a backslash, like so: \2192 (f.e. content: '\2192';)

2.5.0-rc1

8 months ago

2.3.3

2 years ago

2.4.0-rc17

2 years ago

2.4.0-rc18

2 years ago

2.4.0-rc16

3 years ago

2.4.0-rc15

3 years ago

2.4.0-rc14

3 years ago

2.4.0-rc12

3 years ago

2.4.0-rc13

3 years ago

2.4.0-rc11

3 years ago

2.4.0-rc10

3 years ago

2.4.0-rc9

3 years ago

2.4.0-rc8

3 years ago

2.4.0-rc7

4 years ago

2.3.2

4 years ago

2.4.0-rc6

4 years ago

2.4.0-rc5

4 years ago

2.4.0-rc4

4 years ago

2.3.1

4 years ago

2.4.0-rc3

4 years ago

2.4.0-rc2

4 years ago

2.4.0-rc1

4 years ago

2.3.0

4 years ago

2.3.0-rc17

4 years ago

2.3.0-rc16

4 years ago

2.3.0-rc19

4 years ago

2.3.0-rc18

4 years ago

2.3.0-rc1

4 years ago

2.2.4

4 years ago

2.3.0-rc15

4 years ago

2.3.0-rc14

4 years ago

2.3.0-rc13

4 years ago

2.2.3

4 years ago

2.2.2

5 years ago

2.3.0-rc12

5 years ago

2.3.0-rc11

5 years ago

2.3.0-rc10

5 years ago

2.3.0-rc9

5 years ago

2.3.0-rc8

5 years ago

2.3.0-rc7

5 years ago

2.3.0-rc6

5 years ago

2.3.0-rc5

5 years ago

2.3.0-rc4

5 years ago

2.3.0-rc3

5 years ago

2.3.0-rc2

5 years ago

2.3.0-rc

5 years ago

2.2.0

5 years ago

2.1.1-rc2

5 years ago

2.1.1-rc

5 years ago

2.1.0

5 years ago

2.0.1-rc6

5 years ago

2.0.1-rc5

5 years ago

2.0.1-rc4

5 years ago

2.0.1-rc3

5 years ago

2.0.1-rc2

5 years ago

2.1.0-rc

5 years ago

2.0.0

5 years ago

1.11.1

5 years ago

1.11.1-rc

5 years ago

1.11.1-internal2

5 years ago

1.11.1-internal

5 years ago

1.11.0

5 years ago

1.11.0-rc

5 years ago

1.10.2

5 years ago

1.10.2-rc

5 years ago

1.10.1

5 years ago

1.10.1-rc

5 years ago

1.10.0

5 years ago

1.10.0-rc

5 years ago

1.9.2

6 years ago

1.9.1

6 years ago

1.9.1-rc

6 years ago

1.9.0

6 years ago

1.9.0-rc

6 years ago

1.8.2

6 years ago

1.8.2-rc

6 years ago

1.8.1

6 years ago

1.8.1-rc

6 years ago

1.8.0

6 years ago

1.7.4-rc3

6 years ago

1.7.4-rc1.2

6 years ago

1.7.4-rc2

6 years ago

1.7.4-rc1

6 years ago

1.7.3

6 years ago

1.7.2

6 years ago

1.7.2-rc

6 years ago

1.7.1

6 years ago

1.7.0

6 years ago

1.7.0--rc2

6 years ago

1.7.0--rc

6 years ago

1.6.2

6 years ago

1.6.1

6 years ago

1.6.1-rc

6 years ago

1.6.0

6 years ago

1.6.0-rc

6 years ago

1.5.1-rc2

6 years ago

1.4.5-rc-after

6 years ago

1.5.1-rc

6 years ago

1.5.0

6 years ago

1.4.6-rc3

6 years ago

1.4.6-rc2

6 years ago

1.4.6-rc1

6 years ago

1.4.6-rc

6 years ago

1.4.5

6 years ago

1.4.4

6 years ago

1.4.3

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.1-rc7

6 years ago

1.4.1-rc6

6 years ago

1.4.1-rc5

6 years ago

1.4.1-rc4

6 years ago

1.4.1-rc3

6 years ago

1.4.1-rc2

6 years ago

1.4.1-rc

6 years ago

1.4.0

6 years ago

1.4.0-rc4

6 years ago

1.4.0-rc3

6 years ago

1.4.0-rc2

6 years ago

1.4.0-rc

6 years ago

1.3.0

6 years ago

1.3.0-rc4

6 years ago

1.3.0-rc3

6 years ago

1.3.0-rc2

6 years ago

1.3.0-rc

6 years ago

1.2.0

6 years ago

1.2.0-rc4

6 years ago

1.2.0-rc3

6 years ago

1.2.0-rc2

6 years ago

1.2.0-rc

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

1.0.0-rc15

7 years ago

1.0.0-rc14

7 years ago

1.0.0-rc13

7 years ago

1.0.0-rc12

7 years ago

1.0.0-rc11

7 years ago

1.0.0-rc10

7 years ago

1.0.0-rc9

7 years ago

1.0.0-rc8

7 years ago

1.0.0-rc7

7 years ago

0.11.13

7 years ago

1.0.0-rc6

7 years ago

1.0.0-rc5

7 years ago

1.0.0-rc4

7 years ago

1.0.0-rc3

7 years ago

1.0.0-rc2

7 years ago

1.0.0-rc

7 years ago

0.11.12

7 years ago

0.11.11

7 years ago

0.11.10

7 years ago

0.11.9

7 years ago

0.11.8

7 years ago

0.11.7

7 years ago

0.11.6

7 years ago

0.11.5

7 years ago

0.11.4

7 years ago

0.11.3

7 years ago

0.11.2

7 years ago

0.11.1

7 years ago

0.11.0

7 years ago

0.10.9

7 years ago

0.10.8

7 years ago

0.10.7

7 years ago

0.10.6

7 years ago

0.10.5

7 years ago

0.10.5-rc

7 years ago

0.10.4

7 years ago

0.10.3

7 years ago

0.10.3-rc2

7 years ago

0.10.2

7 years ago

0.10.1

7 years ago

0.9.16

7 years ago

0.10.0

8 years ago

0.9.15

8 years ago

0.9.14

8 years ago

0.9.13

8 years ago

0.9.12

8 years ago

0.9.11

8 years ago

0.9.10

8 years ago

0.9.9

8 years ago

0.9.7

8 years ago

0.9.6

8 years ago

0.9.5

8 years ago

0.9.2

8 years ago

0.9.1

8 years ago

0.9.0

8 years ago

0.8.4

8 years ago

0.8.3

8 years ago

0.8.3--rc

8 years ago

0.8.2

8 years ago

0.8.1

8 years ago

0.8.0

8 years ago

0.7.1

8 years ago

0.7.0

8 years ago

0.6.0

8 years ago

0.5.0

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.7-alpha.3

9 years ago

0.3.7-alpha.2

9 years ago

0.3.7-alpha.1

9 years ago

0.3.6

9 years ago

0.3.5

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.3.0-rc-1

9 years ago

0.3.0-rc

9 years ago

0.2.53

9 years ago

0.2.6

9 years ago

0.2.52

9 years ago

0.2.51

9 years ago

0.2.5

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.2.0-alpha

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago