Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Anyone using the Mobile Detect Plugin?

Started by Muut Archive 9 years ago · 14 replies · 1109 views
9 years ago

I'm very interested in using this plugin, and noticed a fairly critical seeming issue on the Github page here stating an issue with Grav's caching.

TWIG
There seems to be an issue when using Grav's page caching.

When enabled the {{ isMobile() }} and {{ isTablet() }} vars only work intermittently on mobiles/tablets and even intermittently gives a false positive resulting in mobile style sheets etc being loaded for desktop browsers.

I haven't had a chance to play with the plugin yet, but couldn't one conceivably just use one of the other functions as a surrogate, or do they all have issues due to Grav's caching, for those of you who have tried it out? For example, you could potentially use

TWIG
{{ mobile_detect() }} which returns tablet, phone or desktop

Look forward to hearing your thoughts!

9 years ago

it works great without cache. but it seems that we need a dedicated cache file for mobile devices with that condition it will work with cache activated

9 years ago

Hi @dimitrilongo,
Thanks for the response (and thanks for creating the Mobile Detect Plugin in the first place!). I'm admittedly not that familiar with grav's caching methods, but it seems like without the cache, Grav would be significantly slower/less optimal? I see the point regarding a mobile-specific cache file being necessary - that makes sense.

9 years ago

you're right, that's why i posted the issue and ask for help, cause i'm not familiar with all caches methods. I hope someone see this thread or the issue to improve the plugin because with this PHP class you can do lot of things, improve user s experience, target audience, etc

9 years ago

@Rhukster or @flaviocopes - sorry for the nooby question, but is there any way I can learn more about gravs cache methods to try implementing this myself?

9 years ago

This internal stuff is really not documented and the best way to learn about it is to read through the code. However, there is this Performance & Caching section in the docs.

Basically the gist is that stuff in .md files is cached, and only cleared when you clear the cach manually, or a change is detected in the timestamp of the file. A workaround is to simply disable the caching for the single page where caching is not wanted. That way you get the benefits of the rest of Grav caching, but your single page is generated each time. Often the speed of this is neglibable in real-world scenarios.

Stuff in Twig templates uses Twig's own caching mechanism that is quite sophisticated, and basically turns Twig into PHP, so things remain dynamic.

9 years ago

Thanks for the response rhukster (and welcome back after the holidays)! I'll dig in to the performance and caching information to see what I can learn. It looks like this will probably fall under the umbrella of the sophisticating twig caching, as that is where this plugin is intended for customzing twig templates further.

9 years ago

maybe exclude some part of the twig from cache, the part where you add condition for mobile for instance. it seems Craft CMS use a twig filter {% cache %}

9 years ago

Actually there is already a TwigCache plugin that does exactly that.

9 years ago

This is awesome- I look forward to giving that a try with the mobile detect plugin. Thanks!

9 years ago

Thanks dimitrilongo - I'm out of town right now but will test that when back. This looks really useful even outside the realm of mobile detect. Cheers!

9 years ago

I never understand the concept of mobile plugin. I mean if you can make your site responsive to like 200px. Why do you need mobile plugin? I was able to make my www.drinkharder.com to do just that without mobile plugin. A good contact form plugin is what we need.

9 years ago

Sometimes you want to serve different HTML or content to mobile clients. That's where it comes in handy.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1349 9 years ago
Archive · by Muut Archive, 9 years ago
2 934 9 years ago
Archive · by Muut Archive, 9 years ago
2 4060 9 years ago
Archive · by Muut Archive, 9 years ago
1 2946 9 years ago
Archive · by Muut Archive, 9 years ago
3 1117 9 years ago