Problem/Motivation
When aggregated/optimized CSS contains @import rules, if the file isn't resolved, the rule is stripped completely.
@import url('my-file.css?a-query-string');
in this case my-file.css is excluded.
Proposed resolution
Strip query parameters prior to checking if a file exists.
Remaining tasks
User interface changes
API changes
Original report by @casey
When a stylesheet is aggregated that contains an @import rule that can't be resolved at runtime (e.g. one that is dynamicly generated like imagecache generates image derivatives), the @import rule is removed. This isn't proper behaviour.
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | css-aggregation-imports-646862-19.patch | 3.21 KB | mgifford |
| #19 | css-aggregation-imports-646862-19.patch | 3.21 KB | jhedstrom |
| #19 | css-aggregation-imports-646862-19-TEST-ONLY.patch | 2.46 KB | jhedstrom |
| #16 | protoindependent.patch | 604 bytes | Xenopathic |
| #12 | snapshot.png | 5.23 KB | valthebald |
Comments
Comment #1
casey commentedComment #2
casey commentedExample
mystylesheet.css
Results in:
"@import url(not-in-file-system-existing-stylesheet.css);" should however not be removed as it is not properly resolved and replaced by its contents.
Comment #3
kkaefer commentedcan we have a test for this?
Comment #4
casey commentedWith test.
Comment #5
casey commentedReroll
Comment #6
casey commentedbump
Comment #7
casey commented#5: cssimportresolvefail.patch queued for re-testing.
Comment #8
casey commentedStill applies
Comment #9
aspilicious commentedJust out of curiosity
Why is
pushed to the left side without spacing?
Comment #10
casey commentedThat's how the Heredoc syntax works; else the string will include whitespace, which it shouldn't.
Patch still applies by the way.
Comment #11
casey commented#5: cssimportresolvefail.patch queued for re-testing.
Comment #12
valthebaldDoes it still apply?
I used the following files:
include1.css:
include2.css:
div.content { font-size:200%}and finally, in module:
Result (text is both red (include1.css) and enlarged (include2.css))

Tested with the latest 8.x and 7.x, with and without CSS aggregation
Comment #13
Wtower commentedSorry to reopen this after so long but I believe the issue is still there.
The original post states specifically that this happens when the css is not in the filesystem, so your test case with include2.css is not valid.
This also happens to me with the following statement in one of my theme's css files.
It seems that the aggregate version ignores the above statement where the url protocol is ommited.
Comment #14
kpaxman commentedI'm having the same issue with protocol-independent URLs. (I want to use protocol-independent URLs so that the site works over both HTTP and HTTPS without complaining about mixed content.)
This works when aggregated:
@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700,400italic,700italic,300,300italic,600,600italic);This gets removed when aggregated:
@import url(//fonts.googleapis.com/css?family=Open+Sans:400,700,400italic,700italic,300,300italic,600,600italic);Comment #15
rjbautista commentedSame issue with Wtower and kpaxman, subscribing...
Comment #16
Xenopathic commentedA quick fix for protocol-independent URLs, enhancing the regex to not match '//...' as well as all URLs of the format 'abc://...'
Comment #17
tjerkdekuijper commentedI confirm #14, this worked for me on a drupal 7.23 install, using with or without css aggregetion.
Comment #18
nvakenSame here, #14 is a valid fix for us.
Comment #19
jhedstromI think this is the proper issue. This happens when query strings are added to the
@importas well. For instance:Attached is a patch along with a test that illustrates the failure.
Comment #21
jhedstromComment #22
jhedstromComment #23
gaele commentedComment #24
mgiffordre-uploading patch #19 for the bots.
Comment #25
wim leersCan we then also add an external CSS file that has a querystring? We should verify that those don't get imported.
Once that test coverage exists, I think we have sufficient assurances to commit this.
Comment #30
duaelfrWow! There are a lot of issues related with @import management.
Cross linking a few.
Comment #35
bradjones1I think this would be resolved by #2936067: CSS aggregation fails on many variations of @import.