Elide Attributes
Configuration
The 'Elide Attributes' filter is enabled by specifying:
- Apache:
ModPagespeedEnableFilters elide_attributes
- Nginx:
pagespeed EnableFilters elide_attributes;
in the configuration file.
Description
The 'Elide Attributes' filter reduces the transfer size of HTML files by removing attributes from tags when the specified value is equal to the default value for that attribute. This can save a modest number of bytes, and may make the document more compressible by canonicalizing the affected tags.
Operation
There are two cases where an attribute value can be removed. First, some attributes are "single-valued" or "boolean", in that the value specified for the attribute is irrelevant -- all that matters is whether the attribute is present or not. In such cases, the filter will remove the value from the tag, leaving only the attribute name.
For example, the following tag:
<button name="ok" disabled="disabled">
can be rewritten to:
<button name="ok" disabled>
The second case is an optional attribute with a default value. If an HTML attribute includes an explicit value for an attribute (perhaps to aid readability) that is equal to the default attribute, the filter will remove the attribute name and value, knowing that the browser will infer the intended attribute anyway. For example, the following tag:
<form method=get>
can be rewritten to:
<form>
Example
You can see the filter in action at www.modpagespeed.com
on this
example.
Requirements
The 'Elide Attributes' filter must be wary of documents with an XHTML doctype, as removing the value from a single-valued attribute will result in invalid XHTML. The filter attempts to recognize XHTML doctype declarations and will disable this rewriting feature in such cases.
Risks
This filter is considered medium risk. It is safe for most pages, but might break CSS formatting on certain pages that match on default attributes that this filter removes. Further, JavaScript can be written that inspects the DOM looking for the presence of certain attributes. Such JavaScript may behave differently on a page which has removed otherwise unnecessary attributes.