brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: fetchpriority="high" in your HTML makes the browser load the hero image first

Html
~/tips/tip-html-fetchpriority-high-lcp

cat ~/tips/tip-html-fetchpriority-high-lcp.md

Tells the browser which image matters most, so the main picture of a page appears sooner.

The big image at the top of a page is often the thing that decides your Largest Contentful Paint. Browsers do not know that until layout is done, so they start it at low priority. You can tell them earlier.

<img src="hero.jpg" alt="..." width="1200" height="600" fetchpriority="high">

fetchpriority takes high, low or auto (the default). web.dev explains why high helps: images in the viewport start at low priority and only get boosted after layout, while the attribute lets the request start high from the beginning.

low is useful too. In a carousel, the web.dev example puts high on the first slide and low on the others, which are hidden anyway.

It also works on <link> and <script>. If your hero is a CSS background, the browser finds it late, so the advice is to preload it and set the priority on the preload:

<link rel="preload" as="image" href="hero.jpg" fetchpriority="high">

Caveats. It is a hint, and what it does to the actual priority depends on the browser. MDN warns to use it sparingly: mark five images as high and you have given the browser nothing to choose with. One image per page is what I’d aim for. Never combine it with loading="lazy" on the same image, since lazy loading delays exactly the image you want early. MDN marks it Baseline since October 2024.

Further reading: MDN: fetchpriority, web.dev: Optimize resource loading with the Fetch Priority API

More Html tips import { format } from "dates"; width="640" height="360" poster="demo.jpg"> The HTML optgroup element puts headings inside a long dropdown srclang="en" label="English" default> An HTML noindex meta tag keeps one page out of search results All Html tips (14) All topics

Link