kriswallsmith/assetic — Issue #193: Avoid duplicates with CssImportFilter 
Author: androa
Created: 2012-02-29 13:56:27+00:00
State: open

If several CSS assets (big-front.css and small-front.css) in a collection uses @import for the same file (shared-front.css), CssImportFilter will end up creating a file with the imported file twice.

```php
$css = new AssetCollection(array(
new HttpAsset('big-front.css'),
new HttpAsset('small-front.css'),
), array(
new CssImportFilter(),
));
```

Consider that both big-front.css and small-front.css contains `@import url(shared-front.css);` this will create a combined file looking like this:

Content from shared-front.css
Content from big-front.css
Content from shared-front.css
Content from small-front.css

While actually doing the duplicate @import should be considered wrong, browsers accept this and only include the shared-front.css once.

Is this something to replicate in CssImportFilter or is it such a bad practice that the CSS should be fixed instead?

My initial thought on how to fix it was to actually adding the assets found by @import to the AssetCollection so that can handle the duplicates like normal. But that seems really troublesome and slow (because of the recursive checking for @imports).