• Resolved gfour

    (@gfour)


    Hi,

    I’m attempting to use a video on my homepage and I want to load different versions of this video based on the user’s screen—whether it’s a mobile or desktop device. I insert the video on the homepage using a shortcode, where I check if the user is on a mobile device ( wp_is_mobile() ), and then I set the appropriate video path.

    The issue I’m encountering is that this functionality works well without caching. However, when I enable page caching, the user sees the initially cached version of the video, regardless of the device they’re using—whether it’s a mobile or desktop. I’ve experimented with both enabling and disabling the ‘Generate separate files for mobile devices’ option.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Hello

    Would it be possible for you to provide a site URL please?

    Thread Starter gfour

    (@gfour)

    I’d rather not publish a URL that might encounter caching issues. Is there an alternative way for me to provide the information you’re requesting?

    Please could you take a look inside the wp-content/cache/wpo-cache folder to see if the mobile-cached page is generated for the page in question after a preload. https://prnt.sc/jr1Lhm0Wymm6

    Thread Starter gfour

    (@gfour)

    Unfortunately, there are no files with the prefix ‘mobile’ within the ‘/wp-content/cache/wpo-cache’ directory even if the corresponding option is enabled and a new preload was successful.

    Thread Starter gfour

    (@gfour)

    Unfortunately, there are no files with the prefix ‘mobile’ within the ‘/wp-content/cache/wpo-cache’ directory even if the corresponding option is enabled and a new preload was successful.

    Plugin Support vupdraft

    (@vupdraft)

    Are you using a plugin display the alternative image.

    Thread Starter gfour

    (@gfour)

    I’m not sure I understand. Could you please clarify what you meant?

    Plugin Support vupdraft

    (@vupdraft)

    Are you using a plugin that decides if

    1.The device is a mobile

    2. What image to display.

    For example one such as this: https://wordpress.org/plugins/specific-content-for-mobile/

    Thread Starter gfour

    (@gfour)

    Oh!! No, I’m not. I just use the following code in the shortcode that loads the video:

    if ( wp_is_mobile() ) {
      /* Display and echo mobile specific stuff here */
      $video_src = '/wp-content/uploads/2023/10/9X16_WEBSITE_01_FINAL.mp4';
      $stall_img = '/wp-content/uploads/2023/10/mobile_screenshot_01.jpg';
     }

    which then echoes the relative HTML:

    echo '<div data-image="" class="home-slide slide-title video"> 
    <video id="homeVideo" class="slide-video slide-media" preload="metadata" autoplay loop muted playsinline poster="' . $stall_img . '">
       <source src="' . $video_src . '" type="video/mp4" /> </video>  
    </div>';
    • This reply was modified 2 years, 5 months ago by gfour.
    • This reply was modified 2 years, 5 months ago by gfour.
    Plugin Support vupdraft

    (@vupdraft)

    If you have the caching enabled on the home page, it is only going to allow one of the images to be displayed (the one that is on the site at the time of the preload). You will need to exclude the page from caching under caching>>advanced settings >>URL’s to exclude from preload

    Thread Starter gfour

    (@gfour)

    So, for some reason I cannot use the “Generate separate files for mobile devices” option in my situation. I would greatly appreciate it if you could explain how this option works, its specifications, limitations and prerequisites, and what steps I should take to serve different files for mobile devices. Unfortunately, the available documentation lacks a detailed description of this option..

    Plugin Support vupdraft

    (@vupdraft)

    This issue is more with the implementation

    wp_is_mobile() 

    How it works: It matches some of device’s native name in the User Agent String. So if someone manipulates the string and send false information, you can not detect what device it is. It does not return any device name it just returns “true” if you are on a desktop device or false if you are on a mobile device.

    How WordPress uses it: WordPress uses it to add or manipulate content which should be only on mobile devices (regardless of size and the actual application) e.g. to add touch scripts, add viewport, mobile class in admin header, adding mobile buttons.

    Effects on caching: If you use caching plugin it is useless. As your code is not executed every time making results unreliable. If you are going to use wp_is_mobile()  then you will need to exclude the page from caching

    If you use a plugin such as WP Touch “Generate separate files for mobile devices” should work.

    Thread Starter gfour

    (@gfour)

    Hi @vupdraft,

    I’m writing to inform you that we have successfully resolved this case. The issue was resolved by disabling and re-enabling wp-optimize. Now, with the “Generate separate files for mobile devices” option enabled, we can display different videos for desktop and mobile using the same shortcodes, where we check the user’s display size with the wp_is_mobile() function.

    Thank you for your support.

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Generate separate files for mobile devices option doesn’t work’ is closed to new replies.