モバイル ユーザーの帯域幅を節約するために、さまざまなデバイス幅でさまざまなサイズの画像を表示したいのですが、画像がまったくない場合もあります。
次のように意図したとおりに機能しますか?
Modernizr.load([{
test: 1025 > window.screen.width,
yep: "mobile.css",
nope: "desktop.css"
}]);
また、次の純粋な css ソリューションも発見しました。これは機能するとされており、必要な場合にのみ画像をロードします。
<div id="test3">
<div></div>
</div>
#test3 div {
background-image:url('images/test3.png');
width:200px;
height:75px;
}
@media all and (max-width: 600px) {
#test3 {
display:none;
}
}
また
<div id="test5"></div>
@media all and (min-width: 601px) {
#test5 {
background-image:url('images/test5-desktop.png');
width:200px;
height:75px;
}
}
@media all and (max-width: 600px) {
#test5 {
background-image:url('images/test5-mobile.png');
width:200px;
height:75px;
}
}
このソリューションのソース: http://timkadlec.com/2012/04/media-query-asset-downloading-results/
しかし、かなり複雑です。
複数の画像バージョンを読み込まないようにする代わりに、modernizr を使用して背景画像を設定するすべての css を読み込むのは良い考えですか?