Skip to main content

filter · CSS filters

Rewrite style attributes with url() (rewrite_style_attributes_with_url)

Category:
CSS
CoreFilters:
Yes
OptimizeForBandwidth:
No
Risk:
Generally safe

rewrite_style_attributes applies CSS rewriting (minification, URL rewriting) to inline style="" attributes on HTML elements. rewrite_style_attributes_with_url (Core filter) does the same but only when the style value contains a url() reference.

When to use it

  • In CoreFilters, the default RewriteLevel: it runs unless you disable it.
  • Risk rating on these docs: Generally safe.

Risks

The CSS filters page lists no specific risks for this filter. If a page misbehaves with it, DisableFilters rewrite_style_attributes_with_url turns it off for the scope you set it in.

Configuration

Enable it in the module configuration, at server, virtual-host or location scope:

Apache

ModPagespeedEnableFilters rewrite_style_attributes_with_url

nginx

pagespeed EnableFilters rewrite_style_attributes_with_url;

IIS (pagespeed.config)

pagespeed EnableFilters rewrite_style_attributes_with_url

It is on by default under CoreFilters; to turn it off:

ModPagespeedDisableFilters rewrite_style_attributes_with_url   # Apache
pagespeed DisableFilters rewrite_style_attributes_with_url;   # nginx
pagespeed DisableFilters rewrite_style_attributes_with_url   # IIS

Scoping, ForbidFilters and the thresholds filters read: Choosing filters .

Live example

Rewrites inline style attributes only when they contain a url() reference.

This filter changes how the page is structured or delivered, not its size, so the example shows a source diff rather than a byte or request reduction.

See the before and after, with the source diff →

Frequently asked questions

What does the rewrite_style_attributes_with_url filter do?
rewrite_style_attributes applies CSS rewriting (minification, URL rewriting) to inline style="" attributes on HTML elements. rewrite_style_attributes_with_url (Core filter) does the same but only when the style value contains a url() reference.
Is rewrite_style_attributes_with_url enabled by default?
Yes. rewrite_style_attributes_with_url is in CoreFilters, the default RewriteLevel, so it runs unless you turn it off with DisableFilters.
How do I turn off rewrite_style_attributes_with_url?
Add ModPagespeedDisableFilters rewrite_style_attributes_with_url on Apache or pagespeed DisableFilters rewrite_style_attributes_with_url; on nginx. On IIS, add pagespeed DisableFilters rewrite_style_attributes_with_url to pagespeed.config.

This page is drawn from the rewrite_style_attributes_with_url entry on CSS filters. Every filter in one table: PageSpeed filters.

Search