Skip to content

Defer loading of badge_only.css? #9134

Closed
@mgeier

Description

@mgeier

Details

The RTD theme is not used, therefore badge_only.css is loaded.

Expected Result

Faster page load?

Actual Result

I don't know if that makes a meaningful difference, but the file https://assets.readthedocs.org/static/css/badge_only.css is loaded right at the beginning of the page load, even though the HTML elements it applies to are inserted into the page much later.
This seems like a waste, doesn't it?

I've played around with https://pagespeed.web.dev/, which reports potential savings of 780 ms (maybe to be taken with a grain of salt, but anyway).

I'm not at all an expert at any of this, but I've read that the CSS can be deferred with something like this:

<link rel="preload" href="my_style.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="my_style.css"></noscript>

The <noscript> fallback is probably not even necessary, since the "badge" itself is loaded with JavaScript.

Has something like this been considered before?

Metadata

Metadata

Assignees

No one assigned

    Labels

    ImprovementMinor improvement to code

    Type

    No type

    Projects

    Status

    Done

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions