Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Measure performance impact of inlining above-the-fold CSS #63

Open
freezy opened this issue Mar 26, 2018 · 0 comments
Open

Measure performance impact of inlining above-the-fold CSS #63

freezy opened this issue Mar 26, 2018 · 0 comments

Comments

@freezy
Copy link
Member

freezy commented Mar 26, 2018

Given that JavaScript takes a lot more time to process than CSS, this probably won't give a significant boost of loading time. However, it's still worth a try. CSS could be extracted with Puppeteer:

const puppeteer = require('puppeteer');

(async () => {

	const url = 'http://localhost:3333';
	const browser = await puppeteer.launch();
	const page = await browser.newPage();

	try {
		// enable coverage
		await page.coverage.startCSSCoverage();

		// load page
		console.log('Opening page at %s...', url);
		await page.goto(url, { waitUntil: 'load' });

		const coverage = await page.coverage.stopCSSCoverage();

		let totalBytes = 0;
		let usedBytes = 0;
		for (const entry of coverage) {
			console.log('# ================ %s ================', entry.url);
			for (const range of entry.ranges) {
				console.log(entry.text.substring(range.start, range.end));
			}
		}
		console.log('Done!');
		await browser.close();

	} catch (err) {
		if (argv.screenshots) {
			await page.screenshot({ path: 'error.png' });
		}
		console.log('ERROR: ', err);
		await browser.close();
		process.exit(1);
	}
})();

However, to do this correctly, the viewport should also be resized, and links should be at least hovered over to get the interactive styles as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant