Google PageSpeed module is an open source server module that can optimise your web server automagically.
It can do things some cool things like:
- Collapse Whitespace
- Combine CSS
- Combine JavaScript
- Defer JavaScript
- Inline CSS & JS
- Lazily Load Images
- Make Images Responsive
- Optimize Images
- Remove Comments
See https://modpagespeed.com/doc/ for full documentation.
For Example, if we wanted to lazily load images we simply add
For Apache
ModPagespeedEnableFilters lazyload_images
For Nginx
pagespeed EnableFilters lazyload_images;
Architecture
I am installing this on a minimal Linode cloud server running:
– Ubuntu 16.10 Yakkety Yak
– Apache/2.4.18
– Nginx/1.11.10
Installing Apache with mod_pagespeed
sudo apt-get install apache2
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb
sudo dpkg -i mod-pagespeed-stable_current_amd64.deb
sudo apt-get -f install
service apache2 restart
then run
curl -I http://domain-or-ip
and you should see in your headers
X-Page-Speed: 1.11.33.4-0
We are successful! we can stop apache to test nginx on the same port.
service apache2 stop
Installing Nginx with ngx_pagespeed
bash <(curl -f -L -sS https://ngxpagespeed.com/install) --nginx-version latest
Add this to your nginx.conf
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
Start Nginx
/usr/local/nginx/sbin/nginx
then run
curl -I http://domain-or-ip
and you should see in your headers
X-Page-Speed: 1.11.33.4-0