Created
August 10, 2019 19:52
-
-
Save RiodeJaneiroo/b4e6d2abe94b3b1145e46fc9926450e3 to your computer and use it in GitHub Desktop.
[Get Google Page Speed Score] PageSpeed Insights API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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