Skip to content

@import rules aren't combined into the minified CSS files #3539

@GeekPress

Description

@GeekPress

Describe the bug
When the minify CSS option is turned on, the @import rules aren't combined into the current CSS file.

This is an important problem for performance:

  • it creates useless HTTP requests
  • The files needs to be preloaded to not decrease the PageSpeed Insight Grade

I did some tests on my side to know if the default behavior of the library was to combined @import rules.

The response is: YES

Please note that only internal @import rules are combined by the library. It means an @import rules from Google Fonts won't be merged.

I did a simple test on smashingcoding website. I minified this file which contains 2 @import rules:
http://smashingcoding.com/wp-content/plugins/forget-about-shortcode-buttons/public/css/button-styles.css

I used the last version of the library by using this code:

<?php
header('Content-type: text/css');
header('Cache-Control: max-age=31536000');

require_once 'minify/Minify.php';
require_once 'minify/CSS.php';
require_once 'path-converter/ConverterInterface.php';
require_once 'path-converter/Converter.php';

use MatthiasMullie\Minify;

$minifier = new Minify\CSS();
$minifier->add('wp-content/plugins/forget-about-shortcode-buttons/public/css/button-styles.css');

echo $minifier->minify();

The result is available here:
http://smashingcoding.com/minify.php

As you can notice the @import rules has been combined into the minified CSS file.

It means we have a problem into WP Rocket to be able to combine the @import rules.

/!\ The $maxImportSize variable doesn't have any relation with this problem. Increasing its value won't have any effect.

To Reproduce
Steps to reproduce the behavior:

  1. Go to smashingcoding.com
  2. Activate the Minify CSS option
  3. Check the source code of the CSS file which starts by http://smashingcoding.com/wp-content/cache/min/1/wp-content/plugins/forget-about-shortcode-buttons/public/css/button-styles-
  4. See error. The @import rules are still present

Expected behavior
The internal @import rules should be combined into the current CSS file.

Backlog Grooming (for WP Media dev team use only)

  • Reproduce the problem
  • Identify the root cause
  • Scope a solution
  • Estimate the effort

Metadata

Metadata

Assignees

Labels

effort: [M]3-5 days of estimated development timemodule: file optimizationpriority: highIssues which should be resolved as quickly as possibleseverity: majorFeature is not working as expected and no work around availabletype: bugIndicates an unexpected problem or unintended behavior

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions