Download
We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

Preload CSS by default

  • #5065
    Avatar photo[anonymous]

    Hi there,

    Here is a small trick that I found useful for you guys: https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content

    By default, you have:

    <link rel="stylesheet" href="{{css "style.css" }}">

    The result with preloading the sheet is:

    <link rel="stylesheet" href="{{css "style.css" }}" rel="preload" as="style">

    It’s simple and it could have a big effect on your page loading and PageSpeed insights. This could be added by default?

    #5076
    Avatar photo[anonymous]

    Your revised example has two rel attributes. That’s an error. It should be

    <link rel="preload" href="{{css "style.css" }}" as="style">

    That said, there’s no reason to make it a default. Some sites will want to preload css. Others will not. Those that want it can change their theme, as no doubt you’ve done.

    Aside: this seems like a poorly thought out extension. What happens when a non-supporting browser encounters it? I wonder why it wasn’t implemented as a new attribute.

    #5077
    Avatar photo[anonymous]

    Correct! Forgot to remove those  😯

    link rel preload is well supported: https://caniuse.com/link-rel-preload

    I don’t see any reasons why you wouldn’t thought. Publii has no hundreds of CSS files, just one so make it ready quicker is a good thing. I do think it is a good idea on slower connection. If a browser doesn’t support it, then it’s simply ignored. More here: https://www.w3.org/TR/preload/#link-type-preload

    #5079
    Avatar photo[anonymous]
    [anonymous] wrote:

    link rel preload is well supported: https://caniuse.com/link-rel-preload

    The issue to me is not “is it well supported”. It’s “how do you deal with browser that don’t support it”. They went with

    <link rel="preload" href="{{css "style.css" }}" as="style">

    They might have instead gone with

    <link rel="stylesheet" preload="preload" href="{{css "style.css" }}">

    or something like that. One statement for all browsers. Those that understand the new preload attribute do something special. Older browsers ignore it and proceed as they always have. I’m just surprised they went with a syntax that will fail in new browsers. Perhaps there’s a reason that I can’t see.

    [anonymous] wrote:

    I don’t see any reasons why you wouldn’t thought. Publii has no hundreds of CSS files, just one so make it ready quicker is a good thing.

    Not every user will want to preload their stylesheet. Some might want to give priority to a javascript file. Or font loading. It should not be included by default, and turned off by those who don’t want it. It’s a new feature; it should be enabled by users who want it.

    #5108
    Avatar photo[anonymous]

    Well, it’s now standardized. Anyway, I suggest, everyone does what they want.