Mobile them works great as long as full page caching is not enabled.
Permalink 1 user found helpful
As described in the tutorial by Andrew there is an event trigger setup to detect for mobile browsers and then change the theme on the fly. This works only when the page caching is not enabled.
For example, when a page has not yet been cached and is visited by an iphone (this is the first request ever for this page) it will always display using the mobile theme until the cache is cleared. This also happens in the opposite way. When a desktop browser visits a page for the first time subsequent requests by mobile browsers will get only the full theme until the cache is cleared.
It appears that dispatch.php which includes /config/site_events.php is being op-code cached.
Hmmm lame.
Anyway around this problem?
For example, when a page has not yet been cached and is visited by an iphone (this is the first request ever for this page) it will always display using the mobile theme until the cache is cleared. This also happens in the opposite way. When a desktop browser visits a page for the first time subsequent requests by mobile browsers will get only the full theme until the cache is cleared.
It appears that dispatch.php which includes /config/site_events.php is being op-code cached.
Hmmm lame.
Anyway around this problem?
how about in your on_start method, if it matches the request where you are showing the iphone
Sh
I'd think that should work?
Sh
I'd think that should work?
Sorry no go.
Looks like I need to do this all in main theme and not using events. Oh well!
Looks like I need to do this all in main theme and not using events. Oh well!
Yeah, unfortunately the iphone theme switcher that I wrote (c5Touch) doesn't support full page caching, and I'm kind of at a loss as to how it might, to be honest. It's definitely in my mind (and it certainly wouldn't be that hard to keep two copies of a full page cached page around, and switch them based on user agent...just another thing to do.)
Hello!
I just sent a pull request allowing to cache distinct page_content base on a list of allowed get vars:
https://github.com/concrete5/concrete5/pull/460...
When adding "mobile" to the allowed vars, you end up with a cached version of the mobile theme.
I hope this can help!
I just sent a pull request allowing to cache distinct page_content base on a list of allowed get vars:
https://github.com/concrete5/concrete5/pull/460...
When adding "mobile" to the allowed vars, you end up with a cached version of the mobile theme.
I hope this can help!
Same problem here. I have a site that has 20-30 second page loads (!). Full page caching fixes the page load time, but then won't switch between mobile and other theme.I haven't been able to code a way around this yet.
I don't know if this is a great idea but the "on_page_view" event fired before View::render()? In dispatcher.php we get
Couldn't we use "on_page_view" event to switch between an m.example.com and a http://www.example.com and then run then switch via domain on the "on_start" event? Wouldn't this cause the cache to see these as two separate pages?
Sorry if I'm missing something and wasting time.
## Fire the on_page_view Event Events::fire('on_page_view', $c, $u); ## now we display (provided we've gotten this far) $v = View::getInstance(); $v->render($c);
Couldn't we use "on_page_view" event to switch between an m.example.com and a http://www.example.com and then run then switch via domain on the "on_start" event? Wouldn't this cause the cache to see these as two separate pages?
Sorry if I'm missing something and wasting time.
Ok... so i figured the domain idea wasn't ideal so i instead based it off of adding mobile=1 to the uri of mobile detected browsers via a redirect on on_page_view
I then add a second event listener to change the site based on the existence of the GET parameter of mobile=1
This works because caching caches based on the URI and adding mobile=1 essentially isolates mobile from desktop browsers in the cache.
Anyhow, I bumped the version to 1.0.1. I would uninstall and delete the old one before testing and of course this has only been tested on my local dev machine so I'm not 100% sure it will work.
Let me know if you try it and if it actually works.
Best Regards,
Mike
I then add a second event listener to change the site based on the existence of the GET parameter of mobile=1
This works because caching caches based on the URI and adding mobile=1 essentially isolates mobile from desktop browsers in the cache.
Anyhow, I bumped the version to 1.0.1. I would uninstall and delete the old one before testing and of course this has only been tested on my local dev machine so I'm not 100% sure it will work.
Let me know if you try it and if it actually works.
Best Regards,
Mike
Thanks Mike, but I couldn't get it to work. I can't get the mobile theme to display on a mobile device using 1.0.1.
Even if I set the following switch to true, the mobile theme doesn't show in the browser:
Even if I set the following switch to true, the mobile theme doesn't show in the browser:
$isMobile = false; // set to true to test mobile..
Bummer. I can't really see what would be different in that regard between the two. Did it at least redirect with adding "mobile=1" to the URI? Only other possible but not likely things is that you are going to an Admin page or you have the mobile_theme_non_mobile cookie set.
I've only tested it on a couple different situations. A shared server, a dedicated and my local dev box. There could be something unique about those setups that isn't typical.
Anyhow, I attached a new version that isn't any different functionally, just cleans up some variables I left over after testing.
Let me know if you ever get it working.
Thanks for trying it out,
Mike
I've only tested it on a couple different situations. A shared server, a dedicated and my local dev box. There could be something unique about those setups that isn't typical.
Anyhow, I attached a new version that isn't any different functionally, just cleans up some variables I left over after testing.
Let me know if you ever get it working.
Thanks for trying it out,
Mike
Fixed it by adding
to the changeOnMobileURI() function:
define('MOBILE_THEME_IS_ACTIVE',true);
to the changeOnMobileURI() function:
public static function changeOnMobileURI() { if(!empty($_GET['mobile'])) { define('MOBILE_THEME_IS_ACTIVE',true); $pkg = Package::getByHandle('mobile_theme'); $themeId = $pkg->config('MOBILE_THEME_ID'); $mobileTheme = PageTheme::getByID($themeId); if($mobileTheme instanceof PageTheme) { // we have to grab the instance of the view // since on_page_view doesn't give it to us $view = View::getInstance(); $view->setTheme($mobileTheme); } } }
That's awesome! You rock.
Hi, I downloaded the 1.0.2 version, installed it and added in the extra line that Fig mentioned and it seems to be working as expected - not showing the desktop version on a mobile device and not showing the mobile version on a desktop when full page caching is enabled. However, this doesn't work when I change my user agent to a mobile device on my desktop computer. If I change my user agent to iPhone, for example, it will show me the mobile version but after switching back to desktop, it will only show the mobile version.
Is there a reason why it won't work when simulating an iPhone on a desktop computer by changing the user agent? I can get by without it but it would be great if worked because it makes testing on mobile devices a lot easier.
Thanks!
Is there a reason why it won't work when simulating an iPhone on a desktop computer by changing the user agent? I can get by without it but it would be great if worked because it makes testing on mobile devices a lot easier.
Thanks!
The current Mobile Theme Switcher doesn't have the most advanced user agent regular expression.
I have a fork on my github that uses the regex from detectmobilebrowsers.com Maybe give that a shot?
https://github.com/mkly/addon_mobile_theme_switcher...
I have a fork on my github that uses the regex from detectmobilebrowsers.com Maybe give that a shot?
https://github.com/mkly/addon_mobile_theme_switcher...
I should also add that it works via adding mobile=1 to the uri. So if you go to the previous uri that you were with the mobile, something like
http://www.example.com/some-page/?mobile=1...
Will always show the mobile no matter what. The URI is how it works with the Zend cache.
http://www.example.com/some-page/?mobile=1...
Will always show the mobile no matter what. The URI is how it works with the Zend cache.
Thanks to you guys for this info! It helped me a lot!
Now I was wondering if it would be advisable to change the path creation in non_mobile.php to get the Pretty URL link when redirecting visitors?
I find it cleaner and seems to give the expected result when you turn on/off Pretty URLs.
Now I was wondering if it would be advisable to change the path creation in non_mobile.php to get the Pretty URL link when redirecting visitors?
//gives "/index.php/path/to/page" //$path = View::url($c->getCollectionPath()); //gives "/path/to/page" $path = NavigationHelper::getLinkToCollection(Page::getByID($_REQUEST['rcID']), true);
I find it cleaner and seems to give the expected result when you turn on/off Pretty URLs.
How can I get around this caching issue?
Right now I'm using the on_start event, is there another I should use instead?