Inline @import to Link

Configuration

The 'Inline @import to Link' filter is enabled by specifying:

Apache:
ModPagespeedEnableFilters inline_import_to_link
Nginx:
pagespeed EnableFilters inline_import_to_link;
in the configuration file.

Description

The "Inline @import to Link" filter converts a <style> tag consisting of only @import statements into the corresponding <link> tags. This conversion does not itself result in any significant optimization, rather its value lies in that it enables optimization of the linked-to CSS files by later filters, in particular the combine_css, rewrite_css, inline_css, and extend_cache filters.

Operation

This filter inspects the contents of all <style> tags and converts the tag if all the following conditions are met:

If all these conditions are met, the <style> tag and its contents are replaced with a <link> tag for each @import, with:

For example, if the <style> tag looks like this:

<style type="text/css" media="screen">@import url(http://www.example.com/style.css);</style>

Then PageSpeed will convert it to:

<link type="text/css" media="screen" rel="stylesheet" href="http://www.example.com/style.css"/>

Example

You can see the filter in action at www.modpagespeed.com on this example.

Risks

This filter is considered minimal risk.