Neil_Bradley
asked on
Prevent a display:none image from downloading on page load
Hi EE
How can I prevent the background image whose containing element is hidden from downloading?
Cheers,
N
If it helps I use the following js to convert the data-background to my background image
<!--this section shows on desktop but is hidden on mobile-->
<section class="bg-image visible-xs visible-sm" data-background-img="uploads/images/full/04.jpg">
</section>
<!--this section is hidden on desktop but shows on mobile-->
<section class="bg-image hidden-xs hidden-sm" data-background-img="uploads/images/full/m/04.jpg">
</section>
Using Chrome tools I see that both the desktop and mobile background images download on page load.How can I prevent the background image whose containing element is hidden from downloading?
Cheers,
N
If it helps I use the following js to convert the data-background to my background image
var pageSection = $('.bg-image');
pageSection.each(function (indx) {
if ($(this).attr("data-background-img")) {
$(this).css("background-image", "url(" + $(this).data("background-img") + ")");
}
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you try like this
Complete Function
include 'Mobile_Detect.php';
$detect = new Mobile_Detect();
// Check for any mobile device.
if ($detect->isMobile())
// mobile content
else
// other content for desktops
Complete Function
function isMobileDevice(){
$aMobileUA = array(
'/iphone/i' => 'iPhone',
'/ipod/i' => 'iPod',
'/ipad/i' => 'iPad',
'/android/i' => 'Android',
'/blackberry/i' => 'BlackBerry',
'/webos/i' => 'Mobile'
);
//Return true if Mobile User Agent is detected
foreach($aMobileUA as $sMobileKey => $sMobileOS){
if(preg_match($sMobileKey, $_SERVER['HTTP_USER_AGENT'])){
return true;
}
}
//Otherwise return false..
return false;
}
ASKER
This is great!
I have adapted it slightly however this simple solution has worked a treat!
Thank you.
Neil
I have adapted it slightly however this simple solution has worked a treat!
Thank you.
Neil
My pleasure. Thanks for the points :)
<!--this section shows on desktop but is hidden on mobile-->
<section class="bg-image visible-xs visible-sm" data-background-img="uploa
</section>
<!--this section is hidden on desktop but shows on mobile-->
<section class="bg-image hidden-xs hidden-sm" data-background-img="uploa
</section>