WordPress.org

Forums

Black Studio Touch Dropdown Menu
Decide with wp_is_mobile() if plugin adds code at all? (3 posts)

  1. Ov3rfly
    Member
    Posted 2 years ago #

    Another idea:

    Would it be possible that the plugin does not call wp_enqueue_script() and wp_localize_script() if not on a mobile device? Some sites do not use jquery, so the extra loading could be avoided if not required.

    WordPress since 3.4 has a function wp_is_mobile() which checks the useragent for certain values and returns a boolean.

    The existing checks for IOS etc. in .js would stay there of course.

    http://codex.wordpress.org/Function_Reference/wp_is_mobile
    http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/vars.php#L106

    Not sure how "safe" wp_is_mobile() is for detection, maybe does not detect enough(?), and probably there should be a function_exists('wp_is_mobile') as well for older WordPress versions...

    http://wordpress.org/extend/plugins/black-studio-touch-dropdown-menu/

  2. Marco Chiesi
    Member
    Plugin Author

    Posted 2 years ago #

    This can be generally a good idea, but it has a major drawback. It doesn't work if the site is using a page caching plugin (W3 Total Cache, WP Super Cache, and similar). In that case the wp_is_mobile() is called only when a user visits a page for the first time, while the following requests for the same page would be served from the cache without checking if it's a mobile device or not.
    Maybe I could add an option or filter hook to manually allow the activation of server-side device detection, so that WordPress admins can use it. Or alternatively I could enable it by default and add an auto-detection for the most popular caching plugin, that disables the server-side device detection if needed.
    What do you think about it?

  3. Ov3rfly
    Member
    Posted 2 years ago #

    You are right about the caching plugins problem.

    Would then suggest to only add an option/filter for admins via function.php

    Would not recommend to enable by default and detect popular plugins.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Black Studio Touch Dropdown Menu
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.