The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

WWW::Google::PageSpeedOnline - Interface to Google Page Speed Online API.

VERSION

Version 0.08

DESCRIPTION

Google Page Speed is a tool that helps developers optimize their web pages by analyzing the pages and generating tailored suggestions to make the pages faster. You can use the Page Speed Online API to programmatically generate Page Speed scores & suggestions. Currently it supports version v1. Courtesy limit is 250 queries per day.

IMPORTANT:The version v1 of the Google Page Speed Online API is in Labs and its features might change unexpectedly until it graduates.

STRATEGIES

    +-------------+
    | Strategy    |
    +-------------+
    | desktop     |
    | mobile      |
    +-------------+

RULES

    +---------------------------------------+
    | Rule                                  |
    +---------------------------------------+
    | AvoidCssImport                        |
    | InlineSmallJavaScript                 |
    | SpecifyCharsetEarly                   |
    | SpecifyACacheValidator                |
    | SpecifyImageDimensions                |
    | MakeLandingPageRedirectsCacheable     |
    | MinimizeRequestSize                   |
    | PreferAsyncResources                  |
    | MinifyCss                             |
    | ServeResourcesFromAConsistentUrl      |
    | MinifyHTML                            |
    | OptimizeTheOrderOfStylesAndScripts    |
    | PutCssInTheDocumentHead               |
    | MinimizeRedirects                     |
    | InlineSmallCss                        |
    | MinifyJavaScript                      |
    | DeferParsingJavaScript                |
    | SpecifyAVaryAcceptEncodingHeader      |
    | LeverageBrowserCaching                |
    | OptimizeImages                        |
    | SpriteImages                          | 
    | RemoveQueryStringsFromStaticResources |
    | ServeScaledImages                     |
    | AvoidBadRequests                      |
    | UseAnApplicationCache                 | 
    +---------------------------------------+

LOCALES

    +-------+------------------------------+
    | Code  | Description                  | 
    +-------+------------------------------+
    | ar    | Arabic                       | 
    | bg    | Bulgarian                    |
    | ca    | Catalan                      |  
    | zh_TW | Traditional Chinese (Taiwan) |
    | zh_CN | Simplified Chinese           |
    | fr    | Croatian                     |
    | cs    | Czech                        |
    | da    | Danish                       |
    | nl    | Dutch                        |
    | en_US | English                      |
    | en_GB | English UK                   |
    | fil   | Filipino                     |
    | fi    | Finnish                      |
    | fr    | French                       |
    | de    | German                       |
    | el    | Greek                        |
    | lw    | Hebrew                       |
    | hi    | Hindi                        |
    | hu    | Hungarian                    |
    | id    | Indonesian                   |
    | it    | Italian                      | 
    | ja    | Japanese                     | 
    | ko    | Korean                       |
    | lv    | Latvian                      |
    | lt    | Lithuanian                   |
    | no    | Norwegian                    |
    | pl    | Polish                       |
    | pr_BR | Portuguese (Brazilian)       |
    | pt_PT | Portuguese (Portugal)        | 
    | ro    | Romanian                     |
    | ru    | Russian                      |
    | sr    | Serbian                      |
    | sk    | Slovakian                    |
    | sl    | Slovenian                    |
    | es    | Spanish                      | 
    | sv    | Swedish                      |
    | th    | Thai                         |
    | tr    | Turkish                      | 
    | uk    | Ukrainian                    | 
    | vi    | Vietnamese                   | 
    +-------+------------------------------+

CONSTRUCTOR

The constructor expects at the least the API Key that you can get from Google for FREE. You can also provide prettyprint switch as well, which can have either true or false values. You can pass param as scalar the API key, if that is the only the thing you would want to pass in. In case you would want to pass prettyprint switch then you would have to pass as hashref like:

    +-------------+----------+----------------------------------------------------------------------------------+
    | Parameter   | Default  | Meaning                                                                          |
    +-------------+----------+----------------------------------------------------------------------------------+
    | api_key     | Required | API Key                                                                          |
    | prettyprint | true     | Returns the response in a human-readable format. Valid values are true or false. |
    +-------------+----------+----------------------------------------------------------------------------------+

    use strict; use warnings;
    use WWW::Google::PageSpeedOnline;
    
    my ($api_key, $page);
    $api_key = 'Your_API_Key';
    $page    = WWW::Google::PageSpeedOnline->new($api_key);
    # or
    $page    = WWW::Google::PageSpeedOnline->new({api_key => $api_key});
    # or
    $page    = WWW::Google::PageSpeedOnline->new({api_key=>$api_key, prettyprint=>'true'});

METHODS

process()

    +-----------+----------+-----------------------------------------------------------------------------------+
    | Parameter | Default  | Meaning                                                                           |
    +-----------+----------+-----------------------------------------------------------------------------------+
    | url       | Required | The URL of the page for which the Page Speed Online API should generate results.  |     
    | locale    | en-US    | The locale that results should be generated in.                                   |
    | strategy  | desktop  | The strategy to use when analyzing the page. Valid values are desktop and mobile. |
    | rule      | N/A      | The Page Speed rules to run. Can have multiple rules something like for example,  |
    |           |          | ['AvoidBadRequests', 'MinifyJavaScript'] to request multiple rules.               |
    +-----------+----------+-----------------------------------------------------------------------------------+

    use strict; use warnings;
    use WWW::Google::PageSpeedOnline;
    
    my ($api_key, $page);
    $api_key = 'Your_API_Key';
    $page    = WWW::Google::PageSpeedOnline->new($api_key);
    $page->process({url => 'http://code.google.com/speed/page-speed/'});

get_stats()

Returns the page stats in XML format, something like below:

    <?xml version="1.0" encoding="UTF-8"?>
    <PageStats>
        <Hosts unit="number">7</Hosts>
        <Request unit="bytes">2711</Request>
        <Response unit="bytes">
                <HTML>92198</HTML>
                <CSS>37683</CSS>
                <Image>13906</Image>
                <Javascript>247174</Javascript>
                <Other>8802</Other>
        </Response>
        <Resources unit="number">
                <Static>16</Static>
                <CSS>2</CSS>
                <Javascript>6</Javascript>
                <Resource>22</Resource>
        </Resources>
    </PageStats>
    
    use strict; use warnings;
    use WWW::Google::PageSpeedOnline;
    
    my ($api_key, $page, $stats);
    $api_key = 'Your_API_Key';
    $page    = WWW::Google::PageSpeedOnline->new($api_key);
    $page->process({url => 'http://code.google.com/speed/page-speed/'});
    $stats   = $page->get_stats();

get_result()

Returns the page result in XML format, like below:

    <?xml version="1.0" encoding="UTF-8"?>
    <PageResults>
        <Rule name="Avoid CSS @import" impact="0" score="100"/>
        <Rule name="Inline Small JavaScript" impact="0" score="100"/>
        <Rule name="Specify a character set" impact="0" score="100"/>
        <Rule name="Specify a cache validator" impact="1" score="75"/>
        <Rule name="Specify image dimensions" impact="0" score="100"/>
        <Rule name="Make landing page redirects cacheable" impact="0" score="100"/>
        ....
        ....
        ....
    </PageResults>
    
    use strict; use warnings;
    use WWW::Google::PageSpeedOnline;
    
    my ($api_key, $page, $result);
    $api_key = 'Your_API_Key';
    $page    = WWW::Google::PageSpeedOnline->new($api_key);
    $page->process({url => 'http://code.google.com/speed/page-speed/'});
    $result  = $page->get_result();

get_advise()

Returns the page advise in XML format, like below:

    <?xml version="1.0" encoding="UTF-8"?>
    <PageAdvise>
        <Rule id="DeferParsingJavaScript">
                <Header>232.9KiB of JavaScript is parsed during initial page load. Defer parsing JavaScript to reduce blocking of page rendering.</Header>
                <Items>
                        <Item>http://code.google.com/js/codesite_head.pack.04102009.js (65.4KiB)</Item>
                        ....
                        ....
                        ....
                </Items>
        </Rule>
        <Rule id="LeverageBrowserCaching">
                <Header>The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:</Header>
                <Items>
                        <Item>http://google-code-feed-gadget.googlecode.com/svn/trunk/images/cleardot.gif (3 minutes)</Item>
                        <Item>http://code.google.com/css/codesite.pack.04102009.css (60 minutes)</Item>
                        ....
                        ....
                        ....
        </Rule>
        ....
        ....
        ....
    </PageAdvise>

    use strict; use warnings;
    use WWW::Google::PageSpeedOnline;
    
    my ($api_key, $page, $advise);
    $api_key = 'Your_API_Key';
    $page    = WWW::Google::PageSpeedOnline->new($api_key);
    $page->process({url => 'http://code.google.com/speed/page-speed/'});
    $advise  = $page->get_advise();

get_score()

Returns the page score.

    use strict; use warnings;
    use WWW::Google::PageSpeedOnline;
    
    my ($api_key, $page, $score);
    $api_key = 'Your_API_Key';
    $page    = WWW::Google::PageSpeedOnline->new($api_key);
    $page->process({url => 'http://code.google.com/speed/page-speed/'});
    $score   = $page->get_score();

get_title()

Returns the page title.

    use strict; use warnings;
    use WWW::Google::PageSpeedOnline;
    
    my ($api_key, $page, $title);
    $api_key = 'Your_API_Key';
    $page    = WWW::Google::PageSpeedOnline->new($api_key);
    $page->process({url => 'http://code.google.com/speed/page-speed/'});
    $title   = $page->get_title();

get_id()

Returns the page id.

    use strict; use warnings;
    use WWW::Google::PageSpeedOnline;
    
    my ($api_key, $page, $id);
    $api_key = 'Your_API_Key';
    $page    = WWW::Google::PageSpeedOnline->new($api_key);
    $page->process({url => 'http://code.google.com/speed/page-speed/'});
    $id      = $page->get_id();

AUTHOR

Mohammad S Anwar, <mohammad.anwar at yahoo.com>

BUGS

Please report any bugs or feature requests to bug-www-google-pagespeedonline at rt.cpan.org or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Google-PageSpeedOnline. I will be notified and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc WWW::Google::PageSpeedOnline

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright 2011 Mohammad S Anwar.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

DISCLAIMER

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.