Google Page Speed for .NET

Description
This little piece of software sends a request to the Google page speed API, then parses the JSON response and presents them in a nice class.

I use this class on this webpage to show the page speed score at the bottom right corner of the site.

Features:
  • Using .NET variables for things like language (CultureInfo) or ResponseCode (HttpStatusCode)
  • Predefined enumerations for ArgumentType, Strategy, SupportedLanguages etc.
  • Uses the 3.5 Framework DataContractJsonSerializer class for deserialization.
  • Automatic combination of the format strings with the arguments.

Here's a sample code how to use it (There is an online demo at http://schaffhauser.me/Development#GooglePageSpeed)

 

// Create the object with your google api key
PageSpeedpageSpeed = newPageSpeed("your-pagespeed-api-key");

// Set properties where necessairy, only the url is mandatory.
pageSpeed.Locale = SupportedLanguages.English;
pageSpeed.PrettyPrint = true;
pageSpeed.Strategy = Strategy.Desktop;
pageSpeed.Url = "http://www.microsoft.com";

// If you dont want to send a server side call to the google pagespeed api, you can
// use this property to go to the google pagespeed webpage
// and start a test for your url.
stringdirectGoogleUrl = pageSpeed.DirectGoogleUrl;

// Get the page speed data for the url from the google pagespeed api
PageSpeedDatadata = pageSpeed.GetPageSpeedData();

Last edited Apr 23, 2012 at 8:58 AM by Darky28, version 2

Comments

No comments yet.