Skip to main content
ModPageSpeed 2.0 and mod_pagespeed 1.1 — Now available

Add instrumentation

HTML

Adds a small client-side beacon that reports real load timings.

Filter add_instrumentation · Filter docs

A mod_pagespeed 1.1 filter. ModPageSpeed 2.0 applies it as part of one always-on pipeline, not as a separate switch.

Both frames render identically — that's the goal. The win is in the bytes and requests below, not the look. They're served live by mod_pagespeed 1.1 on demo-httpd-1.1.modpagespeed.com; the optimized frame applies only this filter. Right after a cache purge it may briefly match the original while the worker rewrites it — reload to see the result.

Measured impact

This filter changes how the page is structured or delivered, not its size — so there's no byte or request reduction to chart. The change shows in the source diff below.

What changed in the source

The page's HTML, before and after this filter. Red lines are removed, green lines are added.


                
                  
<html>
<head>
<title>add_instrumentation example</title>
- </head>
+ <script>window.mod_pagespeed_start = Number(new Date());</script></head>
<body>
A small page to demonstrate how instrumentation is added to a page.
- </body>
+ <script data-pagespeed-no-defer type="text/javascript">//<![CDATA[
+ (function(){window.pagespeed=window.pagespeed||{};var f=window.pagespeed;function h(c,a,e,b){this.j=c;this.g=a;this.h=e;this.l=b}f.beaconUrl="";
+ function k(c){var a=c.j,e=window.mod_pagespeed_start,b=Number(new Date)-e;a+=a.indexOf("?")==-1?"?":"&";a=a+"ets="+(c.g=="load"?"load:":"unload:");if(c.g!="beforeunload"||!window.mod_pagespeed_loaded){a=a+b+("&r"+c.g+"=");if(window.performance){b=window.performance.timing;var d=b.navigationStart,g=b.requestStart;a+=b[c.g+"EventStart"]-d;a+="&nav="+(b.fetchStart-d);a+="&dns="+(b.domainLookupEnd-b.domainLookupStart);a+="&connect="+(b.connectEnd-b.connectStart);a=a+("&req_start="+(g-d))+("&ttfb="+(b.responseStart-
+ g));a+="&dwld="+(b.responseEnd-b.responseStart);a+="&dom_c="+(b.domContentLoadedEventStart-d);window.performance.navigation&&(a+="&nt="+window.performance.navigation.type);d=-1;b.msFirstPaint?d=b.msFirstPaint:window.chrome&&window.chrome.loadTimes&&(d=Math.floor(window.chrome.loadTimes().firstPaintTime*1E3));d-=g;d>=0&&(a+="&fp="+d)}else a+=b;f.getResourceTimingData&&window.parent==window&&(a+=f.getResourceTimingData());a+=window.parent!=window?"&ifr=1":"&ifr=0";c.g=="load"&&(window.mod_pagespeed_loaded=
+ !0,(b=window.mod_pagespeed_num_resources_prefetched)&&(a+="&nrp="+b),(b=window.mod_pagespeed_prefetch_start)&&(a+="&htmlAt="+(e-b)));f.criticalCss&&(e=f.criticalCss,a+="&ccis="+e.total_critical_inlined_size+"&cces="+e.total_original_external_size+"&ccos="+e.total_overhead_size+"&ccrl="+e.num_replaced_links+"&ccul="+e.num_unreplaced_links);a+="&dpr="+window.devicePixelRatio;c.h!=""&&(a+=c.h);document.referrer&&(a+="&ref="+encodeURIComponent(document.referrer));a+="&url="+encodeURIComponent(c.l);f.beaconUrl=
+ a;(new Image).src=a}}f.i=function(c,a,e,b){var d=new h(c,a,e,b);window.addEventListener?window.addEventListener(a,function(){k(d)},!1):window.attachEvent("on"+a,function(){k(d)})};f.addInstrumentationInit=f.i;})();
+
+ pagespeed.addInstrumentationInit('/mod_pagespeed_beacon', 'load', '', 'http://demo-httpd-1.1.modpagespeed.com/mod_pagespeed_example/add_instrumentation.html');
+ //]]></script></body>
</html>