LoginSignup
11
8

More than 3 years have passed since last update.

【HTML】loading属性で“lazy”を指定する場合、widthとheight属性が必要

Last updated at Posted at 2019-09-17

loading属性とは、ブラウザがネイティブで遅延ロードをサポートするというものです。

img要素やiframe要素をHTMLの属性として指定するだけで、JavaScriptを使うことなく、簡単に遅延ロードさせることができます。

例)

<img src="画像パス" loading="lazy" alt="hogehoge">

ところがどっこい、、、

スクリーンショット 2019-09-18 2.43.57.png

[Intervention] An element was lazyloaded with loading=lazy, but had no dimensions specified. Specifying dimensions improves performance. See https://crbug.com/954323

widthとheight属性も同時に指定しないとChromeに怒られてしまいます。

<img src="画像パス" loading="lazy" alt="hogehoge" width="***" height="***">

widthとheight属性を指定してあげれば問題ありません。
本来、横幅・高さ属性というのはレンダリング計算上、必要なものなので。。

11
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
8