Front-office performance hints

Google's mod_pagespeed

Google mod_pagespeed is an Apache HTTPD module that optimizes web pages that it serves, and their associated resources. It's composed of several "filters" that are responsible for rewriting HTML, combining and inlining CSS and JS, and so on. The module behavior and the filter it uses are fully configurable.

The module is currently only available for linux (x86 and x86-64), as a .deb (Debian/Ubuntu) and .rpm (CentOS/Fedora) packages. It can be downloaded on this page : http://code.google.com/speed/page-speed/download.html.

Installation on Debian/Ubuntu

  • Install the package by running the following commands as root:


    $ dpkg -i mod-pagespeed-*.deb
    $ apt-get -f install

  • Check that the module is correctly installed, i.e. the "pagespeed.conf" and "pagespeed.load" files exist in the "/etc/apache2/mods-enabled/" directory.
  • Restart the Apache HTTP server: "/etc/init.d/apache2 restart" or "apache2ctl restart".

Installation on CentOS/Fedora

  • Install the package by running the following commands as root:


    $ yum install at
    $ rpm -U mod-pagespeed-*.rpm

  • Check that the module is correctly installed in "/etc/httpd/conf.d"
  • Restart the Apache HTTP server.

At this point, the module is enabled by default for the entire apache server, on all vhosts. If you want to enable the module only for one or more vhosts, you have to:

  • turn off the ModPagespeed directive in the "pagespeed.conf" file, which will disable the module by default.
  • Enable the module in the configuration of each vhost you want to, by specifying


    <IfModule pagespeed_module>
    ModPagespeed on
    </IfModule>

The exhaustive list of filters used by default and how to enable or disable it are described in this page : http://code.google.com/speed/page-speed/docs/config_filters.html

URL aliases

HTTP 1.1 specifies that browsers should send only two parallel requests to the same host. If you have 40 or more static resources (img, CSS, JS) on a single page, your browser will spend many time waiting to an available slot to download these resources.

A common trick is to have several domains serving your static resources, eg. www1.mydomain.com, www2.mydomain.com, ...

Since version 3.2.1 you can configure Ametys to take advantage of multiple domains for serving static resources.

Follow these steps to set up Ametys accordingly:

  • Point DNS entries of the additional subdomains to the same IP than the main domain
  • Configure the site in Ametys CMS to have several front-office URLs. Be careful to always have the main URL at the first place.

  • Modify your rendering XSLT stylesheets:
    • Declare the AmetysXSLTHelper as a new namespace:
      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                  xmlns:ametys="org.ametys.web.transformation.xslt.AmetysXSLTHelper"
      							exclude-result-prefixes="ametys">
      
    • Locate all usages of the variable $skinContext
      <img src="{$skinContext}/img/banner.png" alt=""/>
      
    • Replace them by ametys:absoluteSkinContext(skin, site) where skin is the name of the current skin and site the name of the current site.
      <img src="{ametys:absoluteSkinContext($skin, $site)}/img/banner.png" alt=""/>
      
  • All calls to ametys:absoluteSkinContext(skin) will be replaced by a random URL taken from all provided front-office URLs

Since version 3.3, you may also use the ametys:absoluteSkinContext(skin, site, path) which ensures that all calls to a given path will correspond to the same random URL, so that the browser properly cache the resource.