Skip to content

Preload Header Overlay Images#5241

Closed
SocksTheWolf wants to merge 1 commit intommistakes:masterfrom
SocksTheWolf:preload-overlay-image
Closed

Preload Header Overlay Images#5241
SocksTheWolf wants to merge 1 commit intommistakes:masterfrom
SocksTheWolf:preload-overlay-image

Conversation

@SocksTheWolf
Copy link
Copy Markdown

@SocksTheWolf SocksTheWolf commented May 22, 2025

This is an enhancement or feature.

Summary

Header images are the most important thing outside of content. While this could also be done in the general custom header file, it's probably best the theme is practicing best practices. Be responsive for all users out of the box.

Adds a liquid check to inject a preload <link> tag with the overlay_image if it's specified.

Context

If the user has overlay images in their page header liquid, make it so we by default, preload those images immediately. This will make the page look responsive and clean.

Header images are the most important thing outside of content. While this could also be done in the general custom header file, it's probably best the theme is practicing best practices. Be responsive for all users out of the box.
@SocksTheWolf SocksTheWolf changed the title Preload Overlay Images Preload Header Overlay Images May 22, 2025
@iBug
Copy link
Copy Markdown
Collaborator

iBug commented Jun 15, 2025

The overlay image is specified in an inline style attribute within the HTML directly, so I'm not confident about how much this will help.

bexelbie added a commit to bexelbie/minimal-mistakes that referenced this pull request Mar 7, 2026
Add a <link rel="preload"> hint for page.header.overlay_image in
<head> so the browser fetches it immediately instead of waiting for
CSS parsing. Only emitted on pages with an overlay image.

Upstream: mmistakes#5241

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bexelbie added a commit to bexelbie/minimal-mistakes that referenced this pull request Mar 7, 2026
Add a <link rel="preload"> hint for page.header.overlay_image in
<head> so the browser fetches it immediately instead of waiting for
CSS parsing. Only emitted on pages with an overlay image.

Upstream: mmistakes#5241

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bexelbie added a commit to bexelbie/minimal-mistakes that referenced this pull request Mar 7, 2026
Add a <link rel="preload"> hint for page.header.overlay_image in
<head> so the browser fetches it immediately instead of waiting for
CSS parsing. Only emitted on pages with an overlay image.

Upstream: mmistakes#5241

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bexelbie added a commit to bexelbie/minimal-mistakes that referenced this pull request Mar 7, 2026
Add a <link rel="preload"> hint for page.header.overlay_image in
<head> so the browser fetches it immediately instead of waiting for
CSS parsing. Only emitted on pages with an overlay image.

Upstream: mmistakes#5241

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bexelbie added a commit to bexelbie/minimal-mistakes that referenced this pull request Mar 9, 2026
Add a <link rel="preload"> hint for page.header.overlay_image in
<head> so the browser fetches it immediately instead of waiting for
CSS parsing. Only emitted on pages with an overlay image.

Upstream: mmistakes#5241

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bexelbie
Copy link
Copy Markdown
Contributor

bexelbie commented Mar 9, 2026

@iBug The preload hint does help because the overlay image URL lives inside an inline style="background-image: url(...)" attribute on a <div> deep in the page body (page__hero.html, line 23). Browser preload scanners reliably find src and href attributes, but don't reliably extract URLs from inline CSS. The <link rel="preload"> in <head> ensures the fetch starts immediately without relying on that heuristic.

In practice, on fast connections and small pages the difference is negligible — but it's a free improvement for the edge cases where it matters (slow connections, large HTML documents), and has no downside since the browser deduplicates if it already found the image.

I've been running this in production on my site. Happy to open a fresh PR if this one can't be updated — the only other nit is the self-closing /> on the <link> tag, which doesn't match the HTML5 style used in the rest of head.html.

@iBug
Copy link
Copy Markdown
Collaborator

iBug commented Mar 9, 2026

@bexelbie I am still not convinced as maintenance overhead is a kind of cost, outside visible performance metrics.

it's a free improvement for the edge cases where it matters

I checked my website and the style=background-url HTML attribute for the overlay image is located at less than 4 KB from the beginning of the file. I can imagine someone with a huge navigation bar would push the overlay image down further, but even then the HTML size before this point will be negligible compared to the image itself (ask: would you put anything smaller than, say, 16 KB, as your header overlay image?)

So I don't think this is the kind of edge case worth "optimizing".

bexelbie added a commit to bexelbie/minimal-mistakes that referenced this pull request Mar 10, 2026
Add a <link rel="preload"> hint for page.header.overlay_image in
<head> so the browser fetches it immediately instead of waiting for
CSS parsing. Only emitted on pages with an overlay image.

Upstream: mmistakes#5241

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@iBug
Copy link
Copy Markdown
Collaborator

iBug commented Mar 11, 2026

This PR is based on theoretical argument of presumed optimization, so I'm not considering this before concrete numbers prove non-trivial improvement.

@iBug iBug closed this Mar 11, 2026
bexelbie added a commit to bexelbie/minimal-mistakes that referenced this pull request Mar 16, 2026
Add a <link rel="preload"> hint for page.header.overlay_image in
<head> so the browser fetches it immediately instead of waiting for
CSS parsing. Only emitted on pages with an overlay image.

Upstream: mmistakes#5241

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bexelbie added a commit to bexelbie/minimal-mistakes that referenced this pull request Apr 20, 2026
Add a <link rel="preload"> hint for page.header.overlay_image in
<head> so the browser fetches it immediately instead of waiting for
CSS parsing. Only emitted on pages with an overlay image.

Upstream: mmistakes#5241

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants