Load critical CSS with internal stylesheet

Hello,
It’s possible to print the content of CSS file?
I have a CSS file in: assets/css/critical.css and I want load all the content of it here:

<style>
  // Internal stylesheet
</style>

Yes, you can do the following:

  	<style><?php echo file_get_contents('assets/css/critical.css') ?></style>
2 Likes

If your questions is answered, it would be nice if you could change the category of topic to Solved @horoman Thanks :smile:

There’s a cleaner way to do it:

<style><?php echo f::read($kirby->roots()->index() . '/assets/css/critical.css') ?></style>

This will take care of always setting the absolute path to the file and f::read is a bit more fail proof.

10 Likes