Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Assets performance, PSI and loadCSS

Started by Francesco 9 years ago · 5 replies · 1607 views
9 years ago

Hi everyone! I decided to open this topic since I have a though time with render blocking css, js and PageSpeed Insights results. Hope you can give me some advices on this.
There is another well discussed topic about performance, but since I'd like to focus only on assets and async-loading css I hope this may be useful for others too.

So here the situation.

  • There are some grav plugins that add render-blocking css and js, is there a way to avoid this or make them load async?
  • If I set a js file to be loaded in async or defer, when pipelined can it become render-blocking or does it mantain its loading setting?
  • And the most crucial for me, render-blocking css. I'm trying to load some css files async using loadCSS with no success. But let me describe what I've done so that you can tell me if I did something wrong.
  1. I created 4 assets collection for css in system.yaml:

<details>
<summary>Collection in system.yaml</summary>

collections:
materialize-css:

</details>

  1. I loaded css in base.html.twig following loadCSS Instructions and Asset Mnager instructions

<details>
<summary>Assets in base.html.twig</summary>

{% block stylesheets %}
{% do assets.addCss('materialize-css', {'priority':110, 'group':'assets-style'}) %}
{% do assets.addCss('async-css', {'group':'assets-style'}) %}
{% do assets.addCss('inline-css', {'group':'inline-style'}) %}
{% do assets.addCss('style-css') %}
{% endblock %}
{{ assets.css('assets-style', {'rel':'preload', 'as':'style', 'onload':"this.rel='stylesheet'"}) }}

TWIG
{% block headjs %}
    <script>
    /*! loadCSS. [c]2017 Filament Group, Inc. MIT License */
    (function(){ ... }());
    /*! loadCSS rel=preload polyfill. [c]2017 Filament Group, Inc. MIT License */
    (function(){ ... }());
    </script>
{% endblock %}

{{ assets.css('inline-style', {'loading': 'inline'}) }}
{{ assets.css('head') }}

</details>

In conclusion:

  • I wanted to load fonts css inline, but they are still render-blocking, any suggestion?
  • Async css works fine without loadCSS scripts (from PSI results) and it's awesome, but many browsers don't recognise rel:preload so loadCSS scripts are necessary from what I've read. When I add those scripts as you can see above, PSI detects all the css files as render-blocking.

Do you have any past experience using loadCSS with grav? Have I done some mistakes?
Many thanks for your help!
Here the PSI RESULTS

👍 1
9 years ago

I am in the same boat as you right now just trying to configure the inline-css and critical css - have you made any headway with this?

9 years ago

This kind of nonsense is exactly why moving to HTTP2 makes sense.

9 years ago

Have you successfully implemented HTTP2 with how grav deals with assets? I have actually gotten the server running just fine with HTTP2 and Grav but having a few issues actually getting the assets to get served correctly

8 years ago

We use HTTP2 on getgrav.org. Just works, no special workarounds required.

7 years ago

If you want to use loadCSS to all of your css files.

TWIG
{{ assets.css('head', {'rel':'preload', 'as':'style', 'onload':'this.rel="stylesheet"'}) }} 

 <noscript>{{ assets.css()|raw }}</noscript>

Please note that loadCSS only works when css_pipeline is enabled

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 54 12 hours ago
Support · by Anna, 3 days ago
2 60 15 hours ago
Support · by Justin Young, 15 hours ago
1 30 15 hours ago
Support · by Duc , 1 week ago
2 65 5 days ago
Support · by Colin Hume, 1 week ago
2 57 5 days ago