Optimizing For Bandwidth
PageSpeed's defaultRewriteLevel ofCoreFiltersis designed to reduce latency, incurring a small risk of page breakage.A related goal, bandwidth reduction, can be achieved with close to zerorisk of web-site breakage:
- Apache:
ModPagespeedRewriteLevel OptimizeForBandwidth
- Nginx:
pagespeed RewriteLevel OptimizeForBandwidth;
This option is suitable for use in a root configuration at ahosting service, CDN, or multi-site setup, in conjunction withInheritVhostConfig.In this mode, PageSpeed does not alter HTML at all. It compressesand transcodes imagesin place, and minifiesJavaScript and CSS. By avoiding changes to URL syntax and to HTML, thepotential problem of user-written JavaScript encountering unexpectedDOM elements is elimimated. There is still latency benefit due to thereduced size of resources, as well as substantial bandwidth reduction.
Bandwidth Savings
The bandwidth savings resulting from this option are, of course,dependent on the source site. Our tests with the defaultsettings for OptimizeForBandwidth indicate an average bandwidthreduction of roughly 37% over the content of 1000 large web sites witha client that is capable of displaying webp images, and 25% improvementwith older clients.
Adding Additional Options
Additional latency optimizations that modify HTML can be layered ontop ofOptimizeForBandwidth by enabling additionalfilters, and altering thePreserveURL settings for CSS, images, or JavaScript. For example, to setup a shared hosting server with OptimizeForBandwidth in the root, butwhere individual sites have addedinline_javascript,lazyload_images andprioritize_critical_css,or simply turned onCoreFilters,the following pagespeed.conf fragment may be used:
- Apache:
ModPagespeedInheritVHostConfig onModPagespeedRewriteLevel OptimizeForBandwidth<VirtualHost *:80> ServerName prioritize_above_the_fold.example.com ModPagespeedEnableFilters inline_javascript,prioritize_critical_css,inline_preview_images</VirtualHost><VirtualHost *:80> ServerName preserve_css_urls_off.example.com ModPagespeedCssPreserveURLs off</Directory><VirtualHost *:80> ServerName core.example.com ModPagespeedRewriteLevel CoreFilters</Directory>
- Nginx:
pagespeed RewriteLevel OptimizeForBandwidth;server { server_name prioritize_above_the_fold.example.com pagespeed EnableFilters inline_javascript,prioritize_critical_css,inline_preview_images}server { server_name preserve_css_urls_off.example.com pagespeed CssPreserveURLs off}server { server_name core.example.com pagespeed RewriteLevel CoreFilters}
In version 1.9.32.1 and later,In PlaceResource Optimization is enabled by default. In earlier versions,turning on OptimizeForBandwidth automatically enables In PlaceResource Optimization to optimize the resources without needingto change their URLs. In these earlier versions, when a VirtualHostoverrides theRewriteLevel toCoreFilers, thatturns off In Place Resource Optimization, but it can be re-enabledexplicitly:
- Apache:
ModPagespeedInPlaceResourceOptimization on
- Nginx:
pagespeed InPlaceResourceOptimization on;
