@automattic/jetpack-critical-css-gen 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/LICENSE.txt +357 -0
- package/README.md +24 -0
- package/SECURITY.md +47 -0
- package/build-browser/bundle.full.js +37567 -0
- package/build-browser/bundle.full.js.map +1 -0
- package/build-browser/bundle.js +4 -0
- package/build-browser/bundle.js.map +1 -0
- package/build-node/browser-interface-playwright.d.ts +53 -0
- package/build-node/browser-interface-playwright.js +94 -0
- package/build-node/browser-interface-playwright.js.map +1 -0
- package/build-node/browser-interface.d.ts +77 -0
- package/build-node/browser-interface.js +124 -0
- package/build-node/browser-interface.js.map +1 -0
- package/build-node/css-file-set.d.ts +100 -0
- package/build-node/css-file-set.js +210 -0
- package/build-node/css-file-set.js.map +1 -0
- package/build-node/errors.d.ts +101 -0
- package/build-node/errors.js +103 -0
- package/build-node/errors.js.map +1 -0
- package/build-node/generate-critical-css.d.ts +24 -0
- package/build-node/generate-critical-css.js +162 -0
- package/build-node/generate-critical-css.js.map +1 -0
- package/build-node/ignored-pseudo-elements.d.ts +8 -0
- package/build-node/ignored-pseudo-elements.js +35 -0
- package/build-node/ignored-pseudo-elements.js.map +1 -0
- package/build-node/minify-css.d.ts +11 -0
- package/build-node/minify-css.js +19 -0
- package/build-node/minify-css.js.map +1 -0
- package/build-node/node.d.ts +5 -0
- package/build-node/node.js +6 -0
- package/build-node/node.js.map +1 -0
- package/build-node/object-promise-all.d.ts +12 -0
- package/build-node/object-promise-all.js +16 -0
- package/build-node/object-promise-all.js.map +1 -0
- package/build-node/style-ast.d.ts +164 -0
- package/build-node/style-ast.js +540 -0
- package/build-node/style-ast.js.map +1 -0
- package/build-node/types.d.ts +14 -0
- package/build-node/types.js +2 -0
- package/build-node/types.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-file-set.js","sourceRoot":"","s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AE,GAAU;QAClC,IAAI,CAAC,SAAS,CAAE,GAAG,CAAE,GAAG,GAAG,CAAC;QAC5B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAE,GAAG,CAAE,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,SAAS;QACR,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;CACD"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export type MetaType = {
|
|
2
|
+
[key: string]: string | number;
|
|
3
|
+
};
|
|
4
|
+
export type ErrorSpec = {
|
|
5
|
+
message: string;
|
|
6
|
+
type: string;
|
|
7
|
+
meta: MetaType;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* SuccessTargetError - Indicates that insufficient pages loaded to meet
|
|
11
|
+
* a specified success target. Contains information about each error that caused
|
|
12
|
+
* problems and the URLs they affect.
|
|
13
|
+
*/
|
|
14
|
+
export declare class SuccessTargetError extends Error {
|
|
15
|
+
readonly isSuccessTargetError: boolean;
|
|
16
|
+
readonly urlErrors: {
|
|
17
|
+
[url: string]: ErrorSpec;
|
|
18
|
+
};
|
|
19
|
+
constructor(urlErrors: {
|
|
20
|
+
[url: string]: UrlError;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Base class for URL specific errors, which can be bundled inside a
|
|
25
|
+
* SuccessTargetError.
|
|
26
|
+
*/
|
|
27
|
+
export declare class UrlError extends Error {
|
|
28
|
+
readonly type: string;
|
|
29
|
+
readonly meta: MetaType;
|
|
30
|
+
constructor(type: string, meta: MetaType, message: string);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* HttpError - Indicates an HTTP request has failed with a non-2xx status code.
|
|
34
|
+
*/
|
|
35
|
+
export declare class HttpError extends UrlError {
|
|
36
|
+
constructor({ url, code }: {
|
|
37
|
+
url: string;
|
|
38
|
+
code: number;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* UnknownError - Indicates that fetch() threw an error with its own error string.
|
|
43
|
+
* Contains a raw (and difficult to translate) error message generated by fetch.
|
|
44
|
+
*/
|
|
45
|
+
export declare class UnknownError extends UrlError {
|
|
46
|
+
constructor({ url, message }: {
|
|
47
|
+
url: string;
|
|
48
|
+
message: string;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* CrossDomainError - Indicates that a requested URL failed due to CORS / security
|
|
53
|
+
* limitations imposed by the browser.
|
|
54
|
+
*/
|
|
55
|
+
export declare class CrossDomainError extends UrlError {
|
|
56
|
+
constructor({ url }: {
|
|
57
|
+
url: string;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* LoadTimeoutError - Indicates that an HTTP request failed due to a timeout.
|
|
62
|
+
*/
|
|
63
|
+
export declare class LoadTimeoutError extends UrlError {
|
|
64
|
+
constructor({ url }: {
|
|
65
|
+
url: string;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* RedirectError - Indicates that a requested URL failed due to an HTTP redirection of that url.
|
|
70
|
+
*/
|
|
71
|
+
export declare class RedirectError extends UrlError {
|
|
72
|
+
constructor({ url, redirectUrl }: {
|
|
73
|
+
url: string;
|
|
74
|
+
redirectUrl: string;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* UrlVerifyError - Indicates that a provided BrowserInterface verifyUrl
|
|
79
|
+
* callback returned false for a page which was otherwise loaded successfully.
|
|
80
|
+
*/
|
|
81
|
+
export declare class UrlVerifyError extends UrlError {
|
|
82
|
+
constructor({ url }: {
|
|
83
|
+
url: string;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* EmptyCSSError - Indicates that a requested URL does not have any CSS in its external style sheet(s) and therefore Critical CSS could not be generated.
|
|
88
|
+
*/
|
|
89
|
+
export declare class EmptyCSSError extends UrlError {
|
|
90
|
+
constructor({ url }: {
|
|
91
|
+
url: string;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* XFrameDenyError - Indicates that a requested URL failed due to x-frame-options deny configuration
|
|
96
|
+
*/
|
|
97
|
+
export declare class XFrameDenyError extends UrlError {
|
|
98
|
+
constructor({ url }: {
|
|
99
|
+
url: any;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SuccessTargetError - Indicates that insufficient pages loaded to meet
|
|
3
|
+
* a specified success target. Contains information about each error that caused
|
|
4
|
+
* problems and the URLs they affect.
|
|
5
|
+
*/
|
|
6
|
+
export class SuccessTargetError extends Error {
|
|
7
|
+
constructor(urlErrors) {
|
|
8
|
+
super('Insufficient pages loaded to meet success target. Errors:\n' +
|
|
9
|
+
Object.values(urlErrors)
|
|
10
|
+
.map(e => e.message)
|
|
11
|
+
.join('\n'));
|
|
12
|
+
// Mark this as a SuccessTargetError in an easy way for other code to check.
|
|
13
|
+
this.isSuccessTargetError = true;
|
|
14
|
+
// Convert any Error object into reliable {message,type,meta} objects.
|
|
15
|
+
this.urlErrors = {};
|
|
16
|
+
for (const [url, errorObject] of Object.entries(urlErrors)) {
|
|
17
|
+
this.urlErrors[url] = {
|
|
18
|
+
message: errorObject.message,
|
|
19
|
+
type: errorObject.type || 'UnknownError',
|
|
20
|
+
meta: errorObject.meta || {},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Base class for URL specific errors, which can be bundled inside a
|
|
27
|
+
* SuccessTargetError.
|
|
28
|
+
*/
|
|
29
|
+
export class UrlError extends Error {
|
|
30
|
+
constructor(type, meta, message) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.type = type;
|
|
33
|
+
this.meta = meta;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* HttpError - Indicates an HTTP request has failed with a non-2xx status code.
|
|
38
|
+
*/
|
|
39
|
+
export class HttpError extends UrlError {
|
|
40
|
+
constructor({ url, code }) {
|
|
41
|
+
super('HttpError', { url, code }, `HTTP error ${code} on URL ${url}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* UnknownError - Indicates that fetch() threw an error with its own error string.
|
|
46
|
+
* Contains a raw (and difficult to translate) error message generated by fetch.
|
|
47
|
+
*/
|
|
48
|
+
export class UnknownError extends UrlError {
|
|
49
|
+
constructor({ url, message }) {
|
|
50
|
+
super('UnknownError', { url, message }, `Error while loading ${url}: ${message}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* CrossDomainError - Indicates that a requested URL failed due to CORS / security
|
|
55
|
+
* limitations imposed by the browser.
|
|
56
|
+
*/
|
|
57
|
+
export class CrossDomainError extends UrlError {
|
|
58
|
+
constructor({ url }) {
|
|
59
|
+
super('CrossDomainError', { url }, `Failed to fetch cross-domain content at ${url}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* LoadTimeoutError - Indicates that an HTTP request failed due to a timeout.
|
|
64
|
+
*/
|
|
65
|
+
export class LoadTimeoutError extends UrlError {
|
|
66
|
+
constructor({ url }) {
|
|
67
|
+
super('LoadTimeoutError', { url }, `Timeout while reading ${url}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* RedirectError - Indicates that a requested URL failed due to an HTTP redirection of that url.
|
|
72
|
+
*/
|
|
73
|
+
export class RedirectError extends UrlError {
|
|
74
|
+
constructor({ url, redirectUrl }) {
|
|
75
|
+
super('RedirectError', { url, redirectUrl }, `Failed to process ${url} because it redirects to ${redirectUrl} which cannot be verified`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* UrlVerifyError - Indicates that a provided BrowserInterface verifyUrl
|
|
80
|
+
* callback returned false for a page which was otherwise loaded successfully.
|
|
81
|
+
*/
|
|
82
|
+
export class UrlVerifyError extends UrlError {
|
|
83
|
+
constructor({ url }) {
|
|
84
|
+
super('UrlVerifyError', { url }, `Failed to verify page at ${url}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* EmptyCSSError - Indicates that a requested URL does not have any CSS in its external style sheet(s) and therefore Critical CSS could not be generated.
|
|
89
|
+
*/
|
|
90
|
+
export class EmptyCSSError extends UrlError {
|
|
91
|
+
constructor({ url }) {
|
|
92
|
+
super('EmptyCSSError', { url }, `The ${url} does not have any CSS in its external style sheet(s).`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* XFrameDenyError - Indicates that a requested URL failed due to x-frame-options deny configuration
|
|
97
|
+
*/
|
|
98
|
+
export class XFrameDenyError extends UrlError {
|
|
99
|
+
constructor({ url }) {
|
|
100
|
+
super('XFrameDenyError', { url }, `Failed to load ${url} due to the "X-Frame-Options: DENY" header`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAI5C,YAAa,SAAwC;QACpD,KAAK,CACJ,6DAA6D;YAC5D,MAAM,CAAC,MAAM,CAAE,SAAS,CAAE;iBACxB,GAAG,CAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAE;iBACrB,IAAI,CAAE,IAAI,CAAE,CACf,CAAC;QAEF,4EAA4E;QAC5E,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;QAEjC,sEAAsE;QACtE,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,KAAM,MAAM,CAAE,GAAG,EAAE,WAAW,CAAE,IAAI,MAAM,CAAC,OAAO,CAAE,SAAS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,EAAE,CAAE,CAAC;IACxE,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,QAAQ;IAC1C,YAAa,EAAE,GAAG,EAAE,WAAW,EAAwC;QACtE,KAAK,CACJ,eAAe,EACf,EAAE,GAAG,EAAE,WAAW,EAAE,EACpB,qBAAsB,GAAI,4BAA6B,WAAY,2BAA2B,CAC9F,CAAC;IACH,CAAC;CACD;AAED;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,QAAQ;IAC3C,YAAa,EAAE,GAAG,EAAmB;QACpC,KAAK,CAAE,gBAAgB,EAAE,EAAE,GAAG,EAAE,EAAE,4BAA6B,GAAI,EAAE,CAAE,CAAC;IACzE,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,QAAQ;IAC1C,YAAa,EAAE,GAAG,EAAmB;QACpC,KAAK,CACJ,eAAe,EACf,EAAE,GAAG,EAAE,EACP,OAAQ,GAAI,wDAAwD,CACpE,CAAC;IACH,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,QAAQ;IAC5C,YAAa,EAAE,GAAG,EAAE;QACnB,KAAK,CACJ,iBAAiB,EACjB,EAAE,GAAG,EAAE,EACP,kBAAmB,GAAI,4CAA4C,CACnE,CAAC;IACH,CAAC;CACD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BrowserInterface } from './browser-interface.js';
|
|
2
|
+
import { FilterSpec, Viewport } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Generates critical CSS for the given URLs and viewports.
|
|
5
|
+
*
|
|
6
|
+
* @param {object} root0 - The options object
|
|
7
|
+
* @param {BrowserInterface} root0.browserInterface - Interface to interact with the browser
|
|
8
|
+
* @param {Function} root0.progressCallback - Optional callback function to report progress
|
|
9
|
+
* @param {string[]} root0.urls - Array of URLs to generate critical CSS for
|
|
10
|
+
* @param {Viewport[]} root0.viewports - Array of viewport sizes to consider
|
|
11
|
+
* @param {FilterSpec} root0.filters - Optional filters to apply to the CSS
|
|
12
|
+
* @param {number} root0.successRatio - Ratio of successful URLs required (default: 1)
|
|
13
|
+
* @param {number} root0.maxPages - Maximum number of pages to process (default: 10)
|
|
14
|
+
* @return {Promise<[string, Error[]]>} A promise that resolves to an array containing the critical CSS string and an array of errors.
|
|
15
|
+
*/
|
|
16
|
+
export declare function generateCriticalCSS({ browserInterface, progressCallback, urls, viewports, filters, successRatio, maxPages, }: {
|
|
17
|
+
browserInterface: BrowserInterface;
|
|
18
|
+
progressCallback?: (step: number, total: number) => void;
|
|
19
|
+
urls: string[];
|
|
20
|
+
viewports: Viewport[];
|
|
21
|
+
filters?: FilterSpec;
|
|
22
|
+
successRatio?: number;
|
|
23
|
+
maxPages?: number;
|
|
24
|
+
}): Promise<[string, Error[]]>;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { BrowserInterface } from './browser-interface.js';
|
|
2
|
+
import { CSSFileSet } from './css-file-set.js';
|
|
3
|
+
import { SuccessTargetError, EmptyCSSError } from './errors.js';
|
|
4
|
+
import { removeIgnoredPseudoElements } from './ignored-pseudo-elements.js';
|
|
5
|
+
import { minifyCss } from './minify-css.js';
|
|
6
|
+
const noop = () => {
|
|
7
|
+
// No op.
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Collate and return a CSSFileSet object describing all the CSS files used by
|
|
11
|
+
* the set of URLs provided.
|
|
12
|
+
*
|
|
13
|
+
* Errors that occur during this process are collated, but not thrown yet.
|
|
14
|
+
*
|
|
15
|
+
* @param {BrowserInterface} browserInterface - interface to access pages
|
|
16
|
+
* @param {string[]} urls - list of URLs to scan for CSS files
|
|
17
|
+
* @param {number} maxPages - number of pages to process at most
|
|
18
|
+
* @return {Array} - Two member array; CSSFileSet, and an object containing errors that occurred at each URL.
|
|
19
|
+
*/
|
|
20
|
+
async function collateCssFiles(browserInterface, urls, maxPages) {
|
|
21
|
+
const cssFiles = new CSSFileSet(browserInterface);
|
|
22
|
+
const errors = {};
|
|
23
|
+
let successes = 0;
|
|
24
|
+
for (const url of urls) {
|
|
25
|
+
try {
|
|
26
|
+
const cssIncludes = await browserInterface.getCssIncludes(url);
|
|
27
|
+
// Convert relative URLs to absolute.
|
|
28
|
+
const relativeUrls = Object.keys(cssIncludes);
|
|
29
|
+
const absoluteIncludes = relativeUrls.reduce((set, relative) => {
|
|
30
|
+
try {
|
|
31
|
+
const absolute = new URL(relative, url).toString();
|
|
32
|
+
set[absolute] = cssIncludes[relative];
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
// Ignore invalid URLs.
|
|
36
|
+
// eslint-disable-next-line no-console
|
|
37
|
+
console.log(`Could not absolutify URL: ${relative}`);
|
|
38
|
+
}
|
|
39
|
+
return set;
|
|
40
|
+
}, {});
|
|
41
|
+
await cssFiles.addMultiple(url, absoluteIncludes);
|
|
42
|
+
const internalStyles = await browserInterface.getInternalStyles(url);
|
|
43
|
+
await cssFiles.addInternalStyles(url, internalStyles);
|
|
44
|
+
// Abort early if we hit the critical mass
|
|
45
|
+
successes++;
|
|
46
|
+
if (successes >= maxPages) {
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
errors[url] = err;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return [cssFiles, errors];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get CSS selectors for above the fold content for the valid URLs.
|
|
58
|
+
*
|
|
59
|
+
* @param {object} param - All the parameters as object.
|
|
60
|
+
* @param {BrowserInterface} param.browserInterface - Interface to access pages
|
|
61
|
+
* @param {object} param.selectorPages - All the CSS selectors to URLs map object
|
|
62
|
+
* @param {string[]} param.validUrls - List of all the valid URLs
|
|
63
|
+
* @param {Array} param.viewports - Browser viewports
|
|
64
|
+
* @param {number} param.maxPages - Maximum number of pages to process
|
|
65
|
+
* @param {Function} param.updateProgress - Update progress callback function
|
|
66
|
+
*
|
|
67
|
+
* @return {Set<string>} - List of above the fold selectors.
|
|
68
|
+
*/
|
|
69
|
+
async function getAboveFoldSelectors({ browserInterface, selectorPages, validUrls, viewports, maxPages, updateProgress, }) {
|
|
70
|
+
// For each selector string, create a "trimmed" version with the stuff JavaScript can't handle cut out.
|
|
71
|
+
const trimmedSelectors = Object.keys(selectorPages).reduce((set, selector) => {
|
|
72
|
+
set[selector] = removeIgnoredPseudoElements(selector);
|
|
73
|
+
return set;
|
|
74
|
+
}, {});
|
|
75
|
+
// Go through all the URLs looking for above-the-fold selectors, and selectors which may be "dangerous"
|
|
76
|
+
// i.e.: may match elements on pages that do not include their CSS file.
|
|
77
|
+
const aboveFoldSelectors = new Set();
|
|
78
|
+
const dangerousSelectors = new Set();
|
|
79
|
+
for (const url of validUrls.slice(0, maxPages)) {
|
|
80
|
+
// Work out which CSS selectors match any element on this page.
|
|
81
|
+
const pageSelectors = await browserInterface.runInPage(url, null, BrowserInterface.innerFindMatchingSelectors, trimmedSelectors);
|
|
82
|
+
// Check for selectors which may match this page, but are not included in this page's CSS.
|
|
83
|
+
pageSelectors
|
|
84
|
+
.filter(s => !selectorPages[s].has(url))
|
|
85
|
+
.forEach(s => dangerousSelectors.add(s));
|
|
86
|
+
// Collate all above-fold selectors for all viewport sizes.
|
|
87
|
+
for (const size of viewports) {
|
|
88
|
+
updateProgress();
|
|
89
|
+
const pageAboveFold = await browserInterface.runInPage(url, size, BrowserInterface.innerFindAboveFoldSelectors, trimmedSelectors, pageSelectors);
|
|
90
|
+
pageAboveFold.forEach(s => aboveFoldSelectors.add(s));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// Remove dangerous selectors from above fold set.
|
|
94
|
+
for (const dangerousSelector of dangerousSelectors) {
|
|
95
|
+
aboveFoldSelectors.delete(dangerousSelector);
|
|
96
|
+
}
|
|
97
|
+
return aboveFoldSelectors;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Generates critical CSS for the given URLs and viewports.
|
|
101
|
+
*
|
|
102
|
+
* @param {object} root0 - The options object
|
|
103
|
+
* @param {BrowserInterface} root0.browserInterface - Interface to interact with the browser
|
|
104
|
+
* @param {Function} root0.progressCallback - Optional callback function to report progress
|
|
105
|
+
* @param {string[]} root0.urls - Array of URLs to generate critical CSS for
|
|
106
|
+
* @param {Viewport[]} root0.viewports - Array of viewport sizes to consider
|
|
107
|
+
* @param {FilterSpec} root0.filters - Optional filters to apply to the CSS
|
|
108
|
+
* @param {number} root0.successRatio - Ratio of successful URLs required (default: 1)
|
|
109
|
+
* @param {number} root0.maxPages - Maximum number of pages to process (default: 10)
|
|
110
|
+
* @return {Promise<[string, Error[]]>} A promise that resolves to an array containing the critical CSS string and an array of errors.
|
|
111
|
+
*/
|
|
112
|
+
export async function generateCriticalCSS({ browserInterface, progressCallback, urls, viewports, filters, successRatio = 1, maxPages = 10, }) {
|
|
113
|
+
// Success threshold is calculated based on the success ratio of "the number of URLs provided", or "maxPages" whichever is lower.
|
|
114
|
+
// See 268-gh-Automattic/boost-cloud
|
|
115
|
+
const successUrlsThreshold = Math.ceil(Math.min(urls.length, maxPages) * successRatio);
|
|
116
|
+
try {
|
|
117
|
+
progressCallback = progressCallback || noop;
|
|
118
|
+
let progress = 0;
|
|
119
|
+
const progressSteps = 1 + urls.length * viewports.length;
|
|
120
|
+
const updateProgress = () => progressCallback(++progress, progressSteps);
|
|
121
|
+
// Collate all CSS Files used by all valid URLs.
|
|
122
|
+
const [cssFiles, cssFileErrors] = await collateCssFiles(browserInterface, urls, maxPages);
|
|
123
|
+
updateProgress();
|
|
124
|
+
// Verify there are enough valid URLs to carry on with.
|
|
125
|
+
const validUrls = browserInterface.filterValidUrls(urls);
|
|
126
|
+
if (validUrls.length < successUrlsThreshold) {
|
|
127
|
+
throw new SuccessTargetError(cssFileErrors);
|
|
128
|
+
}
|
|
129
|
+
// Trim ignored rules out of all CSS ASTs.
|
|
130
|
+
cssFiles.applyFilters(filters || {});
|
|
131
|
+
// Gather a record of all selectors, and which page URLs each is referenced by.
|
|
132
|
+
const selectorPages = cssFiles.collateSelectorPages();
|
|
133
|
+
// Get CSS selectors for above the fold.
|
|
134
|
+
const aboveFoldSelectors = await getAboveFoldSelectors({
|
|
135
|
+
browserInterface,
|
|
136
|
+
selectorPages,
|
|
137
|
+
validUrls,
|
|
138
|
+
viewports,
|
|
139
|
+
maxPages,
|
|
140
|
+
updateProgress,
|
|
141
|
+
});
|
|
142
|
+
// Prune each AST for above-fold selector list. Note: this prunes a clone.
|
|
143
|
+
const asts = cssFiles.prunedAsts(aboveFoldSelectors);
|
|
144
|
+
// Convert ASTs to CSS.
|
|
145
|
+
const [css, cssErrors] = minifyCss(asts.map(ast => ast.toCSS()).join('\n'));
|
|
146
|
+
// If there is no Critical CSS, it means the URLs did not have any CSS in their external style sheet(s).
|
|
147
|
+
if (!css) {
|
|
148
|
+
const emptyCSSErrors = {};
|
|
149
|
+
for (const url of validUrls) {
|
|
150
|
+
emptyCSSErrors[url] = new EmptyCSSError({ url });
|
|
151
|
+
}
|
|
152
|
+
throw new SuccessTargetError(emptyCSSErrors);
|
|
153
|
+
}
|
|
154
|
+
// Collect warnings / errors together.
|
|
155
|
+
const warnings = cssFiles.getErrors().concat(cssErrors.map(s => new Error(s)));
|
|
156
|
+
return [css, warnings];
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
browserInterface.cleanup();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=generate-critical-css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-critical-css.js","sourceRoot":"","sources":["../src/generate-critical-css.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAY,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM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CAAC,EAAE,CAAC,IAAI,KAAK,CAAE,CAAC,CAAE,CAAE,CAAE,CAAC;QAErF,OAAO,CAAE,GAAG,EAAE,QAAQ,CAAE,CAAC;KACzB;YAAS;QACT,gBAAgB,CAAC,OAAO,EAAE,CAAC;KAC3B;AACF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove pseudo elements that are ignored while matching elements above the fold.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} selector - selector to filter.
|
|
5
|
+
*
|
|
6
|
+
* @return {string} selector with ignored pseudo elements removed.
|
|
7
|
+
*/
|
|
8
|
+
export declare function removeIgnoredPseudoElements(selector: string): string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const ignoredPseudoElements = [
|
|
2
|
+
'after',
|
|
3
|
+
'before',
|
|
4
|
+
'first-(line|letter)',
|
|
5
|
+
'(input-)?placeholder',
|
|
6
|
+
'scrollbar',
|
|
7
|
+
'search(results-)?decoration',
|
|
8
|
+
'search-(cancel|results)-button',
|
|
9
|
+
];
|
|
10
|
+
let removePseudoElementRegex;
|
|
11
|
+
/**
|
|
12
|
+
* Builds a RegExp for finding pseudo elements that should be ignored while matching
|
|
13
|
+
* elements that are above the fold.
|
|
14
|
+
*
|
|
15
|
+
* @return {RegExp} A RegExp to use when removing unwanted pseudo elements.
|
|
16
|
+
*/
|
|
17
|
+
function getRemovePseudoElementRegex() {
|
|
18
|
+
if (removePseudoElementRegex) {
|
|
19
|
+
return removePseudoElementRegex;
|
|
20
|
+
}
|
|
21
|
+
const allIgnored = ignoredPseudoElements.join('|');
|
|
22
|
+
removePseudoElementRegex = new RegExp('::?(-(moz|ms|webkit)-)?(' + allIgnored + ')');
|
|
23
|
+
return removePseudoElementRegex;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Remove pseudo elements that are ignored while matching elements above the fold.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} selector - selector to filter.
|
|
29
|
+
*
|
|
30
|
+
* @return {string} selector with ignored pseudo elements removed.
|
|
31
|
+
*/
|
|
32
|
+
export function removeIgnoredPseudoElements(selector) {
|
|
33
|
+
return selector.replace(getRemovePseudoElementRegex(), '').trim();
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=ignored-pseudo-elements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ignored-pseudo-elements.js","sourceRoot":"","sources":["../src/ignored-pseudo-elements.ts"],"names":[],"mappings":"AAAA,MAAM,qBAAqB,GAAG;IAC7B,OAAO;IACP,QAAQ;IACR,qBAAqB;IACrB,sBAAsB;IACtB,WAAW;IACX,6BAA6B;IAC7B,gCAAgC;CAChC,CAAC;AAEF,IAAI,wBAAgC,CAAC;AAErC;;;;;GAKG;AACH,SAAS,2BAA2B;IACnC,IAAK,wBAAwB,EAAG;QAC/B,OAAO,wBAAwB,CAAC;KAChC;IAED,MAAM,UAAU,GAAG,qBAAqB,CAAC,IAAI,CAAE,GAAG,CAAE,CAAC;IACrD,wBAAwB,GAAG,IAAI,MAAM,CAAE,0BAA0B,GAAG,UAAU,GAAG,GAAG,CAAE,CAAC;IAEvF,OAAO,wBAAwB,CAAC;AACjC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,2BAA2B,CAAE,QAAgB;IAC5D,OAAO,QAAQ,CAAC,OAAO,CAAE,2BAA2B,EAAE,EAAE,EAAE,CAAE,CAAC,IAAI,EAAE,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minifies the given CSS, returning it as a string. Any errors that occur are returned
|
|
3
|
+
* in the second positional return value.
|
|
4
|
+
*
|
|
5
|
+
* If the CSS fails to minify, the original content will be returned instead.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} css - CSS to minify.
|
|
8
|
+
*
|
|
9
|
+
* @return {[ string, string[] ]} - Minified CSS and a list of errors returned.
|
|
10
|
+
*/
|
|
11
|
+
export declare function minifyCss(css: string): [string, string[]];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import CleanCSS from 'clean-css';
|
|
2
|
+
/**
|
|
3
|
+
* Minifies the given CSS, returning it as a string. Any errors that occur are returned
|
|
4
|
+
* in the second positional return value.
|
|
5
|
+
*
|
|
6
|
+
* If the CSS fails to minify, the original content will be returned instead.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} css - CSS to minify.
|
|
9
|
+
*
|
|
10
|
+
* @return {[ string, string[] ]} - Minified CSS and a list of errors returned.
|
|
11
|
+
*/
|
|
12
|
+
export function minifyCss(css) {
|
|
13
|
+
const result = new CleanCSS().minify(css);
|
|
14
|
+
if (!result.styles) {
|
|
15
|
+
return [css, result.errors];
|
|
16
|
+
}
|
|
17
|
+
return [result.styles, result.errors];
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=minify-css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minify-css.js","sourceRoot":"","sources":["../src/minify-css.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,WAAW,CAAC;AAEjC;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CAAE,GAAW;IACrC,MAAM,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC,MAAM,CAAE,GAAG,CAAE,CAAC;IAE5C,IAAK,CAAE,MAAM,CAAC,MAAM,EAAG;QACtB,OAAO,CAAE,GAAG,EAAE,MAAM,CAAC,MAAM,CAAE,CAAC;KAC9B;IAED,OAAO,CAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAE,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { BrowserInterfacePlaywright } from './browser-interface-playwright.js';
|
|
2
|
+
export { BrowserInterface } from './browser-interface.js';
|
|
3
|
+
export { generateCriticalCSS } from './generate-critical-css.js';
|
|
4
|
+
export * from './errors.js';
|
|
5
|
+
export declare const version = "0.0.11";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { BrowserInterfacePlaywright } from './browser-interface-playwright.js';
|
|
2
|
+
export { BrowserInterface } from './browser-interface.js';
|
|
3
|
+
export { generateCriticalCSS } from './generate-critical-css.js';
|
|
4
|
+
export * from './errors.js';
|
|
5
|
+
export const version = '0.0.11';
|
|
6
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,cAAc,aAAa,CAAC;AAE5B,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given an object full of promises, resolves all of them and returns an object containing resultant values.
|
|
3
|
+
* Roughly equivalent of Promise.all, but applies to an object.
|
|
4
|
+
*
|
|
5
|
+
* @param {object} object - containing promises to resolve
|
|
6
|
+
* @return {object} - Promise which resolves to an object containing resultant values
|
|
7
|
+
*/
|
|
8
|
+
export declare function objectPromiseAll<ValueType>(object: {
|
|
9
|
+
[key: string]: Promise<ValueType>;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
[key: string]: ValueType;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given an object full of promises, resolves all of them and returns an object containing resultant values.
|
|
3
|
+
* Roughly equivalent of Promise.all, but applies to an object.
|
|
4
|
+
*
|
|
5
|
+
* @param {object} object - containing promises to resolve
|
|
6
|
+
* @return {object} - Promise which resolves to an object containing resultant values
|
|
7
|
+
*/
|
|
8
|
+
export async function objectPromiseAll(object) {
|
|
9
|
+
const keys = Object.keys(object);
|
|
10
|
+
const values = await Promise.all(keys.map(key => object[key]));
|
|
11
|
+
return keys.reduce((acc, key, index) => {
|
|
12
|
+
acc[key] = values[index];
|
|
13
|
+
return acc;
|
|
14
|
+
}, {});
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=object-promise-all.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-promise-all.js","sourceRoot":"","sources":["../src/object-promise-all.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAe,MAEpD;IACA,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAE,MAAM,CAAE,CAAC;IACnC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAE,IAAI,CAAC,GAAG,CAAE,GAAG,CAAC,EAAE,CAAC,MAAM,CAAE,GAAG,CAAE,CAAE,CAAE,CAAC;IAErE,OAAO,IAAI,CAAC,MAAM,CACjB,CAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAG,EAAE;QACrB,GAAG,CAAE,GAAG,CAAE,GAAG,MAAM,CAAE,KAAK,CAAE,CAAC;QAC7B,OAAO,GAAG,CAAC;IACZ,CAAC,EACD,EAAoC,CACpC,CAAC;AACH,CAAC"}
|