• Resolved manaraga

    (@manaraga)


    Good day! Thank you for your great plugin!
    On our site we use the mobile template switching plugin. https://wordpress.org/plugins/any-mobile-theme-switcher/
    In each template (mobile and desctop) there are unique js and css.
    We noticed that the merge and minify does not work correctly. For example, they are cached from the desctop theme and are loaded with mobile mapping and vice versa. How to make it so that everything would work correctly and for each template loaded with the appropriate js and css?

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Raul P.

    (@alignak)

    Hi there,

    FVM merges and minifies only the JS and CSS files that are unique to each pageview, but it depends on the files used, rather than url.

    If let say, your homepage loads with 2 different themes, at least one css file will have a different path, thus FVM will generate different files for each view.

    They should not be cached on desktop and shown on mobile, unless the files are exactly the same and have the exact same path, OR if they are cached by some cache plugin.

    Can you elaborate so I can reproduce the steps?

    Thread Starter manaraga

    (@manaraga)

    I can not publish screenshots here, so I give links to them.
    If you clear the cache and walk through the mobile version, you can see that such files are issued by the cache. https://mygoodknife.com/mobile-js.jpg
    If you then switch to the desktop version, you can see that the JavaScript file in the footer is loaded the same as in the mobile and gives an error.
    https://mygoodknife.com/desktop-js.jpg

    Thread Starter manaraga

    (@manaraga)

    I put all my scripts in the footer and it looks like it helped.

    Plugin Author Raul P.

    (@alignak)

    Hi,

    I’m not 100% sure of how the mobile template switching plugin works, but there are 2 ways of changing the theme based on the useragent.

    One is by using PHP to detect the useragent and then load another theme.
    I suspect this is the method it uses, because they say they are not compatible with cache plugins, thus selling a pro version with support to w3 total cache.

    The second one would be to do it via javascript, thus bypassing PHP.

    —

    So let’s say, a user on desktop accesses your site and the server generates a piece of html that return several css and js files, depending on the theme it uses.

    — default js and css for wordpress and plugins
    — desktop theme js and css files

    Later another user comes on Mobile and is shown another theme:
    — default js and css for wordpress and plugins
    — mobile theme js and css files

    While this is true, FVM will recognize that on the css or js urls, the desktop theme is different from the mobile theme, thus it will generate new files.

    The only exception would be, if the file paths never change, which I assume they do.

    I am guessing here, that the mobile template switching plugin replaces the themes at a much later stage than what FVM uses to determine which theme is in use, https://codex.wordpress.org/Plugin_API/Action_Reference

    In that case, moving your scripts to the footer could solve it, because FVM checks this twice, once in the header and another on the footer.

    Still, I’ll take a look at this in the near future, but I suspect the mobile template switching plugin, using some kind of hack to switch themes, which then naturally would not be detected by FVM, which uses the wordpress api.

    I’ll investigate this and if there is something I can do about it, I’ll push an update.

    Thanks for reporting.

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

The topic ‘Mobile theme switcher’ is closed to new replies.