addyosmani / critical

Extract & Inline Critical-path CSS in HTML pages
Apache License 2.0
10.02k stars 371 forks source link

@import url("a.css"); files get ignored #294

Open mikeytown2 opened 6 years ago

mikeytown2 commented 6 years ago

If you want to take this to the extreme make a webpage that uses this style for loading css

<style type="text/css" media="all">
@import url("a.css");
@import url("b.css");
@import url("c.css");
@import url("d.css");
@import url("e.css");
</style>

When running critical https://import.css.url.com/ it'll spit out this "Error: css should not be empty" even though css files do exist.

bezoerb commented 6 years ago

Inline styles are currently not processed by critical so these imports are invisible to critical. You could work around this by specifying the imported stylesheets in the options like this:

critical.generate({
  css: ['a.css', 'b.css', ...]
});

Even though inline-critical won't process the inline styles either so you would end up with the critical css inlined alongside the inline styles with the @import statements ;)

Why don't you use <link rel="stylesheet"> tags?

mikeytown2 commented 6 years ago

import can in in the CSS as well; this syntax just makes testing it a lot easier. What file would I need to edit in order to do a pull request for this feature? Could you point me the right direction?

bezoerb commented 6 years ago

The stylesheets are extracted with oust You can find this in lib/core.js. The critical css is inlined with inline-critical. So if you like you can prepare a PR on these two packages.