Q: Why use this template syntax instead of a CSS media query?
A: That is a personal preference. But personally, I think hiding content with CSS is not "100% proper" because the browser still loads the HTML code. And it depends on your case too.
Q: Why mobile detection result is wrong? (for example, a mobile phone is not detected as mobile)
A: Try a live demo of the library that I use here:
http://demo.mobiledetect.net/
If the result there is wrong, then their user agent database is incorrect/outdated.
Q: I still want to use this addon with guest page caching enabled, and I only use cutemb_is_mobile() and I don't use other functions such as cutemb_is_chrome().
A: The answer is quite long:
- You should choose, whether you want to enable guest page caching for mobile / non mobile.
If most of your guests are mobile, then you should enable guest page caching for mobile.
And vice versa.
- You create a PHP file, named
guest_page_caching_mobile_detect.php
in your /src/
Open this https://raw.githubusercontent.com/serbanghita/Mobile-Detect/master/Mobile_Detect.php
Copy and paste the content into your guest_page_caching_mobile_detect.php
- Find Line #25
Change into
PHP:
class Guest_Page_Caching_Mobile_Detect
- Backup your
config.php
to your local computer.
- Open your
config.php
file and add these lines (line position doesn't matter)
PHP:
require_once('guest_page_caching_mobile_detect.php');$_detect = new Guest_Page_Caching_Mobile_Detect();
define('MY_IS_MOBILE', intval($_detect->isMobile()));
- Open
/xrc/XF/PageCache.php
, backup a copy to your local computer.
- Find this line (#261):
PHP:
return 'page_' . sha1($uri) . '_' . strlen($uri) . "_s{$styleId}_l{$languageId}_v" . self::CACHE_VERSION;
- Change into:
PHP:
return 'page_' . sha1($uri) . '_' . strlen($uri) . "_s{$styleId}_l{$languageId}_v" . self::CACHE_VERSION.'_m'.constant('MY_IS_MOBILE');
- Save.
- Now guest page caching should work in both mobile & non-mobile.