Optimizing For Bandwidth
PageSpeed's default RewriteLevel
of
CoreFilters
is designed to reduce latency, incurring a small risk of page breakage.
A related goal, bandwidth reduction, can be achieved with close to zero
risk of web-site breakage:
- Apache:
ModPagespeedRewriteLevel OptimizeForBandwidth
- Nginx:
pagespeed RewriteLevel OptimizeForBandwidth;
This option is suitable for use in a root configuration at a hosting service, CDN, or multi-site setup, in conjunction with InheritVhostConfig. In this mode, PageSpeed does not alter HTML at all. It compresses and transcodes images in place, and minifies JavaScript and CSS. By avoiding changes to URL syntax and to HTML, the potential problem of user-written JavaScript encountering unexpected DOM elements is elimimated. There is still latency benefit due to the reduced 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 default settings for OptimizeForBandwidth indicate an average bandwidth reduction of roughly 37% over the content of 1000 large web sites with a client that is capable of displaying webp images, and 25% improvement with older clients.
Adding Additional Options
Additional latency optimizations that modify HTML can be layered on
top of OptimizeForBandwidth
by enabling additional
filters, and altering the Preserve
URL settings for CSS, images, or JavaScript. For example, to set
up a shared hosting server with OptimizeForBandwidth in the root, but
where individual sites have added
inline_javascript,
lazyload_images and
prioritize_critical_css,
or simply turned on CoreFilters,
the following pagespeed.conf fragment may be used:
- Apache:
-
ModPagespeedInheritVHostConfig on ModPagespeedRewriteLevel 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 Place
Resource Optimization is enabled by default. In earlier versions,
turning on OptimizeForBandwidth automatically enables In Place
Resource Optimization to optimize the resources without needing
to change their URLs. In these earlier versions, when a VirtualHost
overrides the RewriteLevel
to CoreFilers
, that
turns off In Place Resource Optimization, but it can be re-enabled
explicitly:
- Apache:
ModPagespeedInPlaceResourceOptimization on
- Nginx:
pagespeed InPlaceResourceOptimization on;