How to block domains in Lighthouse

Carsten Behrens
1 min readJun 6, 2020
Photo by Kolleen Gladden on Unsplash

We all know that third-party JavaScript and Ads have a big impact on performance.

To know how much of an impact third-party JavaScript and Ads have on our performance we need to be able to measure our websites performance without them.

As of now, this feature is not available in Google Chrome directly, so we have to use the Lighthouse CLI.

1. Download the Lighthouse CLI

npm install -g lighthouse

2. Create a Lighthouse config file

module.exports = {
extends: "lighthouse:default",
settings: {
onlyCategories: ["performance"],
blockedUrlPatterns: [
"*upscore.com*",
"*connect.facebook*",
"*google-analytics.com*"
],
},
};

You can use the blockedUrlPatters array to specify which domains you want to block.

"*test.com" // Blocks https://somethingtest.com"*test*"
// Blocks https://somethingtest.com
// Blocks https://testsomething.com

There is no other way to block domains using more complex patterns.

3. Run Lighthouse

lighthouse --config-path=path/to/custom-config.js https://example.com

Make sure to run Lighthouse at least 3 times if you want somewhat accurate results.

Originally published at https://carstenbehrens.com.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Carsten Behrens
Carsten Behrens

No responses yet

Write a response