Aller au contenu

Mirrored documentation

This page is a faithful mirror of the original Apache mod_pagespeed documentation (Apache License 2.0). The upstream project was retired and the modpagespeed.com domain is now operated by an unrelated commercial vendor; we host the original reference so users of nginx-module-pagespeed from GetPageSpeed can rely on a stable copy.

Add Head

Configuration

The 'Add Head' filter is enabled by specifying:

Apache:

ModPagespeedEnableFilters add_head

Nginx:

pagespeed EnableFilters add_head;

in the configuration file, but it is also enabled automatically by several other filters, including combine_heads, move_css_to_head, and add_instrumentation.

Description

The 'Add Head' filter is very simple: it adds a head to the document if it encounters a \<body> tag before finding a \<head> tag.

For example, if the HTML document looks like this:

<html>
  <body>
    <div class="blue yellow big bold">
      Hello, world!
    </div>
  </body>
</html>

Then PageSpeed will rewrite it into:

<html>
  <head>
  </head>
  <body>
    <div class="blue yellow big bold">
      Hello, world!
    </div>
  </body>
</html>

Note

This filter exists primarily to ensure that other filters have a place to insert new tags that needs to be in the head, or that trigger on the closing-tag for a head to perform some other action.

Risks

This filter is considered minimal risk.