Prompt different video file depending on mobile/desktop in Dawn

Hello,

I have a custom liquid block to display a video at the top of my website.

https://2yv8ngrn5v4u7ax8-61036331193.shopifypreview.com

To optimize the video resolution and file size i want to be able to prompt one video file for desktop and another for mobile. To keep the website somewhat lean i dont want the user to have to load the video twice while only one is shown and the other hidden.

Here is the code i use.

video { width: 100%; max-height: 50%; display: block; Margin-top:-100px; padding-top:0px; padding-bottom:0px; }

If someone could help me with this i would be very grateful!

Z

@ZigguZ

sorry for that issue have check but i can’t see any issue can you show me?

@KetanKumar

Thanks for your reply Ketan Kumar.

Im trying to make the website look good on both mobile and desktop while keeping it as lightweight as possible.

The current video is about 4:3 and about a 12mb file. On mobile this format doesn’t look good and the file is also heavy for a phone to load.

If possible id like a solution that keeps the current video for desktop while if viewed by a phone then a different and cropped video is prompted. This to reduce file space and make it look better. Im thinking something like 1:1 and I would crop that separately in a video editing software.

It would be counterintuitive if desktop and mobile would have to load both versions while a hide/show command would dictate what is being prompted. I just need something that promts a specific video file depending on desktop/mobile.

Thanks

Z

@ZigguZ

you have add desktop and mobile

@KetanKumar

Im not a coder, would you be so kind to help me with some code that would achieve this?

Z

@ZigguZ

i mean like this

https://www.mojoin.com/show-shopify-banner-image/

@KetanKumar

Thanks for the guide Ketan Kumar.

I followed it and then changed the new sections into two custom liquid sections so I could add one video for desktop and another for mobile.

The sections work, however, currently the website is showing both the video files stacked.

I guess it is because the guide is meant for the Debut theme and I have Dawn.

There was a snippet of code in the guide to be inserted into ‘theme.css’ but that doesn’t exist in Dawn, I tried ‘base.css’ among others but without success.

  1. What code do I need and where does it need to be to in order to achieve this?

  2. Is it for sure that this method wont cause the user to load both the video files even though only one is shown and the other hidden?

Z

@ZigguZ

yes, please

https://codepen.io/adrianparr/pen/QxMvdj

@KetanKumar

Where should I put the code?

Z

Z

your section

@KetanKumar

I added the HTML code to 2 new trial sections mobile/desktop and the CSS to base.css.

The videos are still stacked and the format looks worse.

Can i please ask you to be a bit more specific?

Z

Did you ever solve this? I have added a custom liquid section with code to display video on homepage but am looking for code so that I can have an alternative video play (different aspect ratio) for those viewing on mobile. Can anyone help?