2025年7月25日金曜日

[HTML]fetchpriority属性で画像等の読み込み優先度を指定する

<img>: 画像埋め込み要素 - HTML | MDN
https://developer.mozilla.org/ja/docs/Web/HTML/Reference/Elements/img#fetchpriority

LCP 画像の優先度を上げる例

<img src="lcp-image.jpg" fetchpriority="high">

Fetch Priority API を使用してリソースの読み込みを最適化する  |  Articles  |  web.dev https://web.dev/articles/fetch-priority?hl=ja#increase-lcp-priority

これは試してみた感じだと他の画像に low も指定した方がいい様な感じ

カルーセルの例(スクロールせずに見える範囲の画像の優先度を下げる)

<ul class="carousel">
<img src="img/carousel-1.jpg" fetchpriority="high">
<img src="img/carousel-2.jpg" fetchpriority="low">
<img src="img/carousel-3.jpg" fetchpriority="low">
<img src="img/carousel-4.jpg" fetchpriority="low">
</ul>

Fetch Priority API を使用してリソースの読み込みを最適化する  |  Articles  |  web.dev https://web.dev/articles/fetch-priority?hl=ja#lower-carousel-priority

CSS 背景として含まれる LCP 画像を早期に検出するには、引き続きプリロードが必要です。背景画像の優先度を上げるには、プリロードに fetchpriority='high' を含めます。

Fetch Priority API を使用してリソースの読み込みを最適化する  |  Articles  |  web.dev https://web.dev/articles/fetch-priority?hl=ja#examples

背景画像でない場合はプリロードも要らないみたいですが

Bloggerだとあまり使いどころは無いですが、テンプレートをカスタマイズしていたり、大きなヘッダーイメージがある場合は有効かと

F(uriouz)

欲しいものリスト / 優先度の高いほしいものリスト / ☕を奢る
Donate 寄付 カンパ サポート Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.
詳細プロフィールを表示

0 comments:

スパム対策の為コメントをオフにしています。
Disqusは利用出来ます。

注: コメントを投稿できるのは、このブログのメンバーだけです。

...

Recent Posts

 
"The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License."