Do you want to make your website much faster by making minimum changes to the code? If yes, use Apache's mod_pagespeed
module, which will take care of web optimization best practices automatically after properly setting up and configuring.
Before diving deep into this module, let's analyze your website score using Google's page analysis online tool, which will not only check all the best practices to make your website faster, but will provide you detailed information about what changes are needed to make it more responsive and fast. Check the following URL: https://developers.google.com/speed/pagespeed/insights.
The preceding URL will show you a textbox where you need to enter your website name and click on ANALYZE, as shown in the following screenshot:
After a few seconds, it will give you a score on a scale of 100 and on the left you can find the suggestion list categorized by the priority level.
For Alien Coders, it is 90 out of 100, with some suggestions for best practices, as shown in the following screenshot:
There are a lot of things to do with this module, which we can't just explain as it requires another book to explain it fully with real-life examples. We will try to cover the basic things to get started with. So, mod_pagespeed
is an Apache 2.x module, which is added into an existing Apache server with the help of the pagespeed.cong
configure file. Here, we will deal only with the basics of installing and configuring the mod_pagespeed
module. You may explore the rest of the work easily after that as follows:
Install
mod_pagespeed
. Currently it supports only:CentOS/Fedora (32 bit and 64 bit)
Debian/Ubuntu (32 bit and 64 bit)
So, to install it on Debian or Ubuntu, please run the following command, make sure you are as root:
pkg -i mod-pagespeed-*.deb apt-get -f install
To install it on CentOS or Fedora, please execute the following commands as a root:
yum install at # In case you don't have "at" installed which is required to download rpm package rpm -U mod-pagespeed-*.rpm
So it installs
mod_pagespeed.so
for Apache 2.2 andmod_pagespeed_ap24.so
for Apache 2.4, upgradable configuration filespagespeed.conf
,pagespeed_libraries.conf
in Fedora, andpagespeed.load
on Debian provided you don't change these files ever and JavaScript minifierpagespeed_js_minify
mod_pagespeed Configuration
The
mod_pagespeed
configuration directives should be wrapped inside anIfModule
module as follows:<IfModule pagespeed_module>#config lines here</IfModule>
An example of the
mod_pagespeed
configuration that can be used as a guideline is as follows:# This page shows statistics about the mod_pagespeed # module. <Location /mod_pagespeed_statistics> Order allow, deny # One may insert other "Allow from" lines to add hosts that # are allowed to look at generated statistics. Another # possibility is to comment out the "Order" and "Allow" # options from the config file, to allow any client that # can reach the server to examine statistics. This might be # appropriate in an experimental setup or if the Apache # server is protected by a reverse proxy that will filter # URLs to avoid exposing these statistics, which may reveal # site metrics that not be shared otherwise. Allow from localhost Allow from 127.0.0. SetHandler mod_pagespeed_statistics </Location>
The output filter is used to parse, optimize, and re-serialize HTML content that is generated elsewhere in the Apache server as follows:
# Direct Apache to send all HTML output to the # mod_pagespeed output handler. AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html
It is noteworthy to mention that
mod_pagespeed
automatically enablesmod_deflate
for compression.To turn
mod_pagespeed
on, insert at the top line ofpagespeed.conf: ModPagespeed on
To turn it off, just write
ModPagespeed off
To disable it permanently, write
ModPagespeed unplugged
You just need to install mod_pagespeed
properly for the first time and need to remember how to disable or enable it. That's it. The rest of the configuration settings that set filters are already set at the best for your website by Google developers. If you wish to explore more and want to make settings, configurations, and filters according to your requirements, you must go through the PageSpeed documentation provided by Google.
Once Apache gets started and you start to visit any website, send the PageSpeed statistics to the stats
folder. By default, it will set the localhost to 127.0.0.1, but you can allow more sites as per your needs.
If you host a website and have no control over mod_pagespeed
, try the browser's plugin from https://developers.google.com/speed/pagespeed/,and perform the following steps:
Check Download link at the right-bottom corner for Firefox and Chrome.
Once you download the plugin and restart your browser, open any website to analyze the speed. Then press F12 to turn on the plugin, select the PageSpeed tab, and click on Run Analyze.
Once that is done, you will be able to see something like the following screenshot, which will explain all the errors, warnings, and remedies for the given site:
Click on the text Expand All, as shown in the preceding screenshot to see all the suggestions listed by Google to make the website much more faster and efficient.