I am working on a website (with Statamic v3 which uses Antlers, Bootstrap, SCSS) which involves different uploads for mobile and desktop backgrounds (inline styling). What is the best way to do this? I am struggling quite a while with these kind of questions. Ofcourse I can use display none and display block with media queries, but I'm hoping for a solution where only the mobile image loads on mobile/ small screen sizes, and only the desktop image loads on desktop/ big screen sizes so it is better for the page load.
For the img tag it is possible to use the img srcset, but with an background image that is not possible. I am also questioning myself how I can do this with partials/ elements with just a lot of code (so not necessarily with background images)
I also tried to use the mobile detect with JavaScript, but the problem with that is if the user is working on desktop but with a small browser view, it doesn't get the 'mobile version' of the website.
I mostly end up with using Bootstraps d-none and d-block with media queries, but that doesn't feel right.
Anyone has a best practice for this with keeping good pageload in mind?
Edit: I added some code to show what I am trying to achieve. The user can upload a desktop background image, and a mobile background image at the CMS. As far as I know both of these images will be loaded into the page, but they won't show at the same time because of the display properties. My goal is that the page won't load both of the images, but only the image that is needed on that viewport size. I can't do this inside my SCSS with media queries, because I can't set the background url's inside my SCSS.
<div class="row d-md-none main-content" style="background-image: url('{{ bg_image_desktop }}')">
<div class="offset-md-2 col-md-8">
<h1></h1>
</div>
</div>
<div class="row d-none d-md-block main-content" style="background-image: url('{{ bg_image_mobile }}')">
<div class="col-12">
<h1></h1>
</div>
</div>