The 'Trim URLs' filter is enabled by specifying:
pagespeed EnableFilters trim_urls;
in the configuration file.
This filter trims URLs by resolving them by making them relative to the base
URL for the page. E.g. on
"http://www.example.com/foo" would be shortened to
"foo". The filter works only on URLs that are the values
It also trims image URLs in CSS if
rewrite_css is enabled.
The filter reduces the transfer size of HTML files by shortening most of the URLs. Depending on the HTML file, this filter can significantly reduce the number of bytes transmitted on the network.
The 'Trim URLs' filter removes unnecessary bytes on the wire. While it's useful for development to fully specify your URLs so that links don't break when things move around, these are bytes that are sent unnecessarily on the wire.
For example, if the HTML document looks like this:
<html> <head> <base href="http://www.example.com/"> </head> <body> <a href="http://www.example.com/bar">Link with long URL</a> <img src="http://www.othersite.example.org/image.jpg"> </body> </html>
Then PageSpeed will rewrite it to:
<html> <head> <base href="http://www.example.com/"> </head> <body> <a href="bar">Link with long URL</a> <img src="/fresh_abs_link_error//www.othersite.example.org/image.jpg"> </body> </html>
You can see the filter in action at
www.modpagespeed.com on this
Only URLs referenced by
src attributes and,
rewrite_css is enabled,
URLs in CSS files are rewritten. URLs that occur elsewhere are not altered.
Trimming URLs is considered medium risk. It can cause problems if it uses the wrong base URL. This can happen, for example, if you serve HTML that will be pasted verbatim into other HTML pages. If URLs are trimmed on the first page, they will be incorrect for the page they are inserted into. For this reason, it is off by default.