"Fossies" - the Fresh Open Source Software Archive

Member "incubator-pagespeed-mod-" (28 Feb 2020, 7754 Bytes) of package /linux/www/apache_httpd_modules/incubator-pagespeed-mod-

Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the incubator-pagespeed-mod- project site itself.

Add Instrumentation


The 'Add Instrumentation' filter is enabled by specifying:

ModPagespeedEnableFilters add_instrumentation
pagespeed EnableFilters add_instrumentation;

in the configuration file.


The 'Add Instrumentation' filter injects two small blocks of JavaScript into every HTML page. These blocks measure the time the client spends loading and rendering the page, and report that measurement back to the server.


An empty HTML file passed through the add_instrumentation filter will come out like this (the inserted whitespace is for documentation readability):

    <script type='text/javascript'>
      window.mod_pagespeed_start = Number(new Date());
    <script type='text/javascript'>
      function g(){
        new Image().src = '/mod_pagespeed_beacon?ets=load:'
          + (Number(new Date())-window.mod_pagespeed_start);
      var f = window.addEventListener;
      if (f) {
      } else {
        if (f) {


You can see the filter in action at www.modpagespeed.com on this example.


The first script tag is inserted at the beginning of the document's <head>. It simply records the current time in a global variable. This is placed as early in the document as possible in order to best approximate the beginning of the page load.

The second script tag is inserted at the end of the document's <body>, so as to minimally interfere with page rendering. It registers a listener for the page's onLoad event; this listener computes the total time since the first script tag ran, and sends the result back to the server asynchronously by using a fake Image object. This technique should work on most modern browsers. [1].

The add_instrumentation filter sends a beacon after the page onload handler is called. The user might navigate to a new URL before this. If you enable the following directive, the beacon is sent as part of an onbeforeunload handler, for pages where navigation happens before the onload event.

ModPagespeedReportUnloadTime on
pagespeed ReportUnloadTime on;
By default, the target of the asynchronous callback is the relative URL "/mod_pagespeed_beacon" (Apache) or "/ngx_pagespeed_beacon" (Nginx). PageSpeed handles these results itself and simply returns "204 No Content" which should cause minimal disruption for the client. It also records the number of callbacks, and the total of their onLoad times, in the statistics "page_load_count" and "total_page_load_ms". These are visible on the PageSpeed statistics page (which, by default, is only viewable from the server's localhost). You can divide total_page_load_ms by page_load_count to get the average onLoad time for your site.

You can change the location of the beacon to a different path (or even a different server) using the BeaconUrl directive. For example:

ModPagespeedBeaconUrl "/my/path/to/beacon"
pagespeed BeaconUrl "/my/path/to/beacon";

Or, if you want to set up your own beacon server somewhere else, you can use:

ModPagespeedBeaconUrl "http://my.other.server/my_beacon"
pagespeed BeaconUrl "http://my.other.server/my_beacon";

If you want to set an https beacon URL that is different from the http beacon URL (for example a different machine as shown below, or a non-default port), you can do so by separating the http and https URLs with a space. You don't need to do this if the beacon URLs only differ in protocol (http versus https):

ModPagespeedBeaconUrl "http://insecure.server/my_beacon https://secure.server/my_beacon"
pagespeed BeaconUrl "http://insecure.server/my_beacon https://secure.server/my_beacon";

Note that the BeaconUrl used to require that custom beacon URLs end with "?ets=". Appending the query param to the custom URL is no longer required and should be removed if present.

If you want more detailed information about client load time (e.g. averages for different pages and different browsers, median times, historical behavior, etc.) you can get this information from your webserver logs. Every beacon load will be in your access.log along with the timestamp, referer, IP address, and user-agent—which tell you when, where, and by whom the onLoad measurement was taken. There are some existing tools to collect and analyze these data; one such example is Jiffy.


The "Add Instrumentation" filter requires the "Add Head" filter, and will enable it automatically.


This filter could break pages if they include JavaScript which depends on knowing the first child of the <head> or the last child of the <body>.

The injected JavaScript is very lightweight, and should cause only a very tiny (though nonzero) amount of extra load on the client.

If you already have a client-side latency measurement system in place (such as Jiffy, Episodes, or Boomerang), you probably don't need this filter.

Note that the data reported by this filter is only approximate and does not include time the client spends resolving your domain, opening a connection, and waiting for the first few bytes of HTML.


  1. Zakas, Nicholas C., High Performance JavaScript. O'Reilly, 2010, p133.