Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/run-pagespeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const baseUrl = 'https://www.googleapis.com/pagespeedonline/v5/runPagespeed';

async function runPagespeed(urlString, strategy) {
const url = new URL(urlString);
url.searchParams.append('pagespeed-nocache', Date.now());
if(!url.hash) {
// bust PSI cache but not your CDN's cache
url.hash = `#${Date.now().toString().substring(6)}`
}
const queryOptions = {
url: url.toString(),
strategy: strategy || 'mobile',
Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/run-pagespeed.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`run-pagespeed runPageSpeed calls Desktop API and returns Lighthouse result 1`] = `
Array [
"https://www.googleapis.com/pagespeedonline/v5/runPagespeed/?url=https%3A%2F%2Fwww.google.com%2F%3Fpagespeed-nocache%3D1479427200000&strategy=desktop",
"https://www.googleapis.com/pagespeedonline/v5/runPagespeed/?url=https%3A%2F%2Fwww.google.com%2F%237200000&strategy=desktop",
Object {
"json": true,
},
Expand All @@ -11,7 +11,7 @@ Array [

exports[`run-pagespeed runPageSpeed calls Mobile API and returns Lighthouse result 1`] = `
Array [
"https://www.googleapis.com/pagespeedonline/v5/runPagespeed/?url=https%3A%2F%2Fwww.google.com%2F%3Fpagespeed-nocache%3D1479427200000&strategy=mobile",
"https://www.googleapis.com/pagespeedonline/v5/runPagespeed/?url=https%3A%2F%2Fwww.google.com%2F%237200000&strategy=mobile",
Object {
"json": true,
},
Expand Down