Skip to content

Instantly share code, notes, and snippets.

@RiodeJaneiroo
Created August 10, 2019 19:52
Show Gist options
  • Save RiodeJaneiroo/b4e6d2abe94b3b1145e46fc9926450e3 to your computer and use it in GitHub Desktop.
Save RiodeJaneiroo/b4e6d2abe94b3b1145e46fc9926450e3 to your computer and use it in GitHub Desktop.
[Get Google Page Speed Score] PageSpeed Insights API
var url = 'artzm.space';
var url = (!url.match(/^[a-zA-Z]+:\/\//)) ? 'http://' + url : url;
// Google Page Speed
jQuery.ajax({
url: "https://www.googleapis.com/pagespeedonline/v5/runPagespeed",
type: "GET",
data: {
"strategy": "desktop", // or mobile
"fields": "lighthouseResult/categories/*/score",
"category": "performance",
"url": url,
},
})
.done(function(data, textStatus, jqXHR) {
scoreDesktopG = data['lighthouseResult']['categories']['performance']['score'] * 100;
$('.js-bPrcy__insightsDesktop').text(scoreDesktopG);
}).fail(function(jqXHR, textStatus, errorThrown) {scoreDesktopG = 'Ошибка';});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment