Help us understand the problem. What is going on with this article?

LaravelでインラインCSS

More than 1 year has passed since last update.

PageSpeed Insightsの点数を上げるだけならインラインCSS化が一番効く。
HTTP/2 Server Pushの時代に意味があるかはともかく。(Server Pushの話はどこかに書いた)
どちらがいいかを試すためにインラインCSSもできるようにしておく。

@inline_css('css/app.css')みたいに使えるようにBladeで拡張すればいいと思って作りかけたけど
https://readouble.com/laravel/5.6/ja/blade.html#extending-blade

        Blade::directive('inline_css', function ($path) {
            $css = File::get(public_path(trim($path, "'")));

            return '<style type="text/css">' . $css . '</style>';
        });

作ってる途中で$pathに'が含まれてることに気付く。'css/app.css'で渡される。
そういう仕様?

Blade拡張を集めたパッケージを調べたらそれでも'を削除してた。仕様だ。
https://github.com/appstract/laravel-blade-directives/blob/47424072001279063e69fd117e4fe1c1e4e5ce2d/src/DirectivesRepository.php#L35

そしてここで@inlineがあるのに気付く。自分で作らなくてもこれ使えばいい。
https://github.com/appstract/laravel-blade-directives#inline
@inline('css/app.css')

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away