mod_pagespeed improves website performance and reduces page load time. This Google open-source Apache/Nginx web server module automatically applies web performance best practice to pages, and associated assets (CSS, JavaScript, images) without requiring modification of the application environment.
How does mod_pagespeed speed up web-sites?
From the Pagespeed project website: mod_pagespeed improves web page latency and bandwidth usage by changing the resources on that web page to implement web performance best practices. Each optimization is implemented as a custom filter in mod_pagespeed, which are executed when the Apache HTTP server serves the website assets. Some filters simply alter the HTML content, and other filters change references to CSS, JavaScript, or images to point to more optimized versions.
mod_pagespeed implements custom optimization strategies for each type of asset referenced by the website, to make them smaller, reduce the loading time, and extend the cache lifetime of each asset. These optimizations include combining and minifying JavaScript and CSS files, inlining small resources, and others. mod_pagespeed also dynamically optimizes images by removing unused meta-data from each file, resizing the images to specified dimensions, and re-encoding images to be served in the most efficient format available to the user.
mod_pagespeed ships with a set of core filters designed to safely optimize the content of your site without affecting the look or behavior of your site. In addition, it provides a number of more advanced filters which can be turned on by the site owner to gain higher performance improvements.
mod_pagespeed can be deployed and customized for individual web sites, as well as being used by large hosting providers and CDN’s to help their users improve performance of their sites, lower the latency of their pages, and decrease bandwidth usage.
Mod_Pagespeed Installation
wget wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.rpm rpm -U rpm -U mod-pagespeed-stable_current_i386.rpm
see here: http://linuxdrops.com/speed-up-apache-using-mod_pagespeed-module-from-google-on-centos-rhel-fedora-debian-ubuntu/
Apache Virtual Host Configuration
Jeremy Edgell provides the following Drupal 7 oriented virtual host configuration which can be tailored to local requirements:
<IfModule pagespeed_module> AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html ModPagespeed on ModPagespeedLowercaseHtmlNames on ModPagespeedEnableFilters extend_cache ModPagespeedEnableFilters insert_dns_prefetch # # Text / HTML # ModPagespeedEnableFilters collapse_whitespace ModPagespeedEnableFilters convert_meta_tags ModPagespeedEnableFilters remove_comments ModPagespeedEnableFilters elide_attributes ModPagespeedEnableFilters trim_urls ModPagespeedEnableFilters pedantic # # JavaScript # ModPagespeedEnableFilters combine_javascript ModPagespeedEnableFilters canonicalize_javascript_libraries ModPagespeedEnableFilters rewrite_javascript # Risk ModPagespeedEnableFilters defer_javascript ModPagespeedEnableFilters inline_javascript # # CSS # ModPagespeedEnableFilters rewrite_css ModPagespeedEnableFilters combine_css ModPagespeedEnableFilters move_css_to_head ModPagespeedEnableFilters inline_css ModPagespeedEnableFilters inline_import_to_link ModPagespeedEnableFilters move_css_above_scripts # # Images # ModPagespeedEnableFilters inline_preview_images ModPagespeedEnableFilters insert_img_dimensions ModPagespeedEnableFilters rewrite_images ModPagespeedEnableFilters recompress_images ModPagespeedEnableFilters convert_jpeg_to_progressive ModPagespeedEnableFilters resize_mobile_images ModPagespeedEnableFilters sprite_images ModPagespeedEnableFilters lazyload_images # Risk ModPagespeedEnableFilters local_storage_cache </IfModule>
Mod_Pagespeed Accelerator Configuration
Varnish/Nginx Caches use cache headers to improve performance and these are modified by default by mod_pagespeed. In order to allow these accelerators to cache the mod_pagespeed generated files the following configuration option should be included in the virtual host configuration
<IfModule pagespeed_module> ModPagespeedModifyCachingHeaders off </IfModule>
Documentation related to this option can be found here, background information explaining why mod_pagespeed disables caching can be found here.
Preserving HTML caching headers
From the project website: “… By default, mod_pagespeed serves all HTML with Cache-Control: no-cache, max-age=0 because the transformations made to the page may not be cacheable for extended periods of time.
If you want to force mod_pagespeed to leave the original HTML caching headers you can add:
ModPagespeedModifyCachingHeaders off
Note: We do not suggest you turn this option off. It breaks mod_pagespeed’s caching assumptions and can lead to unoptimized HTML being served from a proxy caches set up in front of the server. If you do turn it off, we suggest that you do not set long caching headers to HTML or users may receive stale or unoptimized content. …”
Disabling Mod_Pagespeed
To disable mod_pagespeed for a specific virtual host include the following directive in the virtual host configuration:
<IfModule pagespeed_module> ModPagespeed off </IfModule>