How easy would it be to have Boost cache files on a per theme basis?
I have a bi-lingual site with a PC version and then using mobile tools it switches theme and serves up 3 different mobile sites depending which carrier you hit it with.
So when I tried it out, the cached PC site's files showed up instead of the mobile ones.
Also the mobile pages I visited then became the pages for the PC site.
Is this easily done?
*Also I am using a j_mobile helper to put the mobile content into j_shift for Japanese phones.
The cached mobile pages returned UTF-8 content.... but that's a different issue.
Any help would be great, because it really puts a snag on the site I built.
Comments
Comment #1
mikeytown2 commentedBoost caches by URL, if you can figure out a way to serve the different themes via a different URL then caching will work for you. Setting up a sub domains for the mobile sites is key. Putting the mobile detection logic at the web server level is the key as well. Quick google search brought up these 2 articles
http://ohryan.ca/blog/2009/02/18/revisiting-mobile-redirection-using-hta...
http://ohryan.ca/blog/2007/10/29/htaccess-mobile-browser-redirect/
Setting up another subdomain just for j_mobile and detecting that phone via user agent is how to handle that situation and others like it. If the content is the same for all 3 sites this module will allow you to reach your goal a lot faster
http://drupal.org/project/domain
Comment #2
Bensbury commentedThanks.
I'll have a look at that.
My problem is that my CTO told me not to use sub-domains because that is not the correct way to do it, so I cannot use a redirect or other domain to hold the mobile site.
He likes to serve up the pages depending on what you hit the website with.
They built www.anapnet.com and it uses the same urls switching content depending on carrier.
It's also fast.
He doesn't like Drupal because he thinks everything should be custom built and so enjoys it when Drupal can't do something.
Comment #3
mikeytown2 commentedYou can use htaccess to serve the page from the subdomain with out redirecting, so to the outside user web address looks the same; and with the domain access module it will act as 1 site. Only people on the inside will know your site is running from many subdomains.
Another other option is to use a different caching module, one that runs from within PHP; look into ways people make Drupal run fast for authenticated users; memcache ect. Using a cache in front of the web server like varnish or squid might work if it respects the user agent.
You can also not use Drupal and waste a lot of time.
Comment #4
Bensbury commentedThanks.
I'll look into the .htaccess method.
I have the memcache working already for authenticated uses, so now I am trying to handle the anonymous visitors.
This is a little hardcore for me as I used hang around in the Flash IDE and code html.... then I took the slippery slide into AS3, PHP, then mysql and now I am heading into apache/linux turf :)
I looked at APC and Squid but I don't think I'll get permissions to install them on the server.
I just have to reduce the CPU hit the site is taking when visitors come from the queries Drupal keeps making.
So if I can find a PHP and mySQL cache without needing to compile something on the server I should be safe.
I want to use Drupal but recently I have found myself in anti-drupal territory.
Also as not a coder, I get put up against it when pulled over for things like performance tweaking.
It kinda sucks when the argument is generally 'I can do this already, so why can't you'.
Comment #5
Bensbury commentedWould it be possible to use the cache specific pages part, to avoid caching if the theme is mobile.
That way the PC version would be super fast and the mobile version would run normally.
That buys me time to figure out how to get the whole thing running with boost.
However if it still involves urls then that part won't work I guess.
Comment #6
mikeytown2 commentedTaking a copy and paste approach to this problem try these htaccess rules
Comment #7
Bensbury commentedThanks.
I'll try that out soon as I can.
/////
I have come with a plan I'm trying to figure out:
Drupal appears to cache differently dependent on role (I think).
Therefore would there be a role based cache solution... with different cache's depending on url.
If so, I think I can assign a role based on pc/mobile and mobile type..... use the role to switch the theme and then cache each version based on the role.
Comment #8
Ela commentedBensbury, Did you figure this out and got it working?
Comment #9
cyberwolf commentedSubscribing.
Comment #10
sachbearbeiter commentedsubscribe
Comment #11
gausarts commentedSubscribing. Thanks
Comment #12
mikeytown2 commentedMore food for thought...
http://httpd.apache.org/docs/trunk/mod/mod_rewrite.html#rewritemap
http://drupalhigh.onsugar.com/How-use-Apache-modrewrite-RewriteMap-direc...
Comment #13
jjwhitney commentedI use Drupal's normal caching mechanism, and I don't know anything about Boost, but I found a great solution that keeps Drupal from serving the wrong (cached) pages to the mobile (or desktop) browser.
The browser_theme source includes a file called "cache.inc" that I placed somewhere in my Drupal installation and added this line to my settings.php file: "$conf['cache_inc'] = './sites/all/modules/browser_theme/cache.inc';". The browser_theme project page describes how it works in the section "Page Caching". (I use mobile_theme, not browser_theme, but their cache solution worked great anyway.)
Good luck!
Comment #14
mikeytown2 commentedlooking at cache.inc; unfortunately this doesn't translate over to Apache rules very well.... see #6 as an attempt at using HTTP_USER_AGENT.
First step for anything like this is to create a mobile directory inside the cache folder. Long story short it can be done; I just haven't gotten enough feedback on the rules in #6. Once I have gotten some sort of feedback I can then start to work on a solution. I first need to know what HTTP_USER_AGENT values are considered mobile. Once I know that the rest will fall into place; this is not that hard to do...
Comment #15
adchavez commented@mikeytown2 I tested the rewrite rules in #6 and it seems to be working for me. I'm using ThemeKey to serve different themes to mobile/desktop users and they're both getting the appropriate themes.
However, it doesn't appear that the mobile pages are being served from the cache ... Is that expected behavior?
Comment #16
mikeytown2 commentedIt's the first step; I need to make a mobile dir and have the rewrite rules point to that instead of normal
Comment #17
adchavez commentedMakes sense. Also, you ask about user agents ... maybe browscap can help there? That's about all I can offer. This is above my pay grade but that seems to be the option of choice for most of the theme-switching modules.
Comment #18
arielkung commentedHello guys, here is my solution (currently on production). Maybe it's not the best solution and you could make some adjustments, but It works fine.
We use mobile tools module with 3 themes:
- Default theme
- Theme for blackberry and android
- Theme for iphone and ipod
We redirect all the devices whit .htaccess to the mobile version of the site except android, iphone, etc. (it depends if you leave this devices get the full versions or not).
So, the trick is the following example code in .htaccess BEFORE boost rules:
Now we have a different url for each theme: the original for the default theme, plus another two with custom querystrings for the bb and iphone theme.
Thus, boost writes one file for each theme. Of course, boost flushes each file on expiration so this doesn't generate garbage.
Enjoy!
Comment #19
minus commentedThank you arielkung!
At our site, the mobile version won't update. If an editor creates a new article, the top story shows on the desktop version, but not on the mobile version. Any suggestions?
Best Regards
Morten
Comment #20
mikeytown2 commentedAfter reading this I thought about setting an environment variable to let drupal know its a mobile device. This could allow for other things in the future besides mobile or normal.
I still haven't tested the PHP/Drupal side of the equation, but at least the htaccess rules are done. So in your settings.php file do something like this & it should work!
Let me know! Crawler won't hit the mobile version; it would have to run every url twice one for each site type. Also cache flushing won't work either... this is at least a step in the right direction.
Comment #21
udvranto commentedSubscribing.
Comment #22
ancky commentedSubscribing.
Comment #23
ancky commentedHi
Just found this topic and they suggest to use Apache Mobile Filter as a solution
I am trying to implement this solution on my project, with this we can retrieve device capabilities in environment variables.
for example we can retrive : $_SERVER['AMF_MAX_IMAGE_HEIGHT'];
this will return the : "MAX_IMAGE_HEIGHT" value which they retrieve from WURFL database
with this we can create a group based on the values retrieved from WURFL like "RESOLUTION_WIDTH"
will get back once I manage to implement this
Comment #24
As If commentedSubscribing. Currently using Boost and a custom useragent theme-branching module, trying to separate the two sets of cached pages without using a subdomain. Here's what my client considers mobile (regexp against the useragent string): "palmos", "palmsource", "pda", "blackberry", "nokia", "hand", "mobi", "phone", "alcatel", "eric", "iphone", "ipod", "midp", "cldc", "android", "psp".
Comment #25
As If commented@mikeytown2 - You rock. Environment variables are totally the way to go.
I am currently running a variant of this approach in my htaccess file, and generating 3 separate caches based on useragent (the caches are called normal, mobile, and applemobile). It's working perfectly. The magic part looks like this...
...then of course I am using
cache/%{ENV:device}instead ofcache/normalMy next goal is to get flushes working for all 3 of those caches. Individually if possible, but even just a total sweep of all caches would be good.
UPDATE 20 May 2011: While I have made a little headway into the idea of flushing these caches individually, this question has become less vital since I found that all my caches are affected when I check the "Flush all sites caches in this database" option.
Comment #26
Ela commented... which solution should we try? #18 or #20?
Comment #27
As If commentedThe biggest difference between those approaches is that #18 uses a domain name to rewrite mobile requests to, while #20 uses environment variables and therefore it does not matter whether or not you have a separate mobile domain. That's the main reason I use a variation of #20. My mobile URLs are the same as my nonmobile URLs.
But I also love the fact that Mikeytown2 pointed out: You can set an environment variable in htaccess and retrieve it in settings.php. That simple fact implies possibilities that go way beyond the scope of this thread. Yay!
Comment #28
ancky commented@As If Hi Im also using cache/%{ENV:device} to create my cache folder based on device capabilities generated by the Apache Mobile Filter
currently I'm having trouble in flushing all the caches folder. because when I flush the cache only one folder get flushed.
I group my cache folder based on device width, currently I have four (4) cache folder they are :
320, 240, 176 and 128 but when I flush my cache only the 320 Folder get flushed. the other folder will still be available. I also have checked the "Flush all sites caches in this database" but the other cache folder is still there and not flushed.
do you have any other ways in flushing all these folders?
thanks
Comment #29
As If commentedI think "Flush all sites caches in this database" worked for me. I'll have to go back and check, but I'm pretty sure.
Comment #30
aludescher commentedhere's my alternative solution, using a subdomain, but some of the .htaccess rules could be applied here, too
Making a Boost cached site mobile
Comment #31
spacereactor commented#20 i got few question this. Where do i add the below code? template.php, settings.php??
And how do i them allow mobile users to switch from mobile theme to desktop theme display and stay in desktop with cookie?
And i using nginx server, is there are a guide on nginx setting, currently the rewrite work for apache.
Comment #32
As If commentedYou can put it in either file, because the value gets set in .htaccess and is thereafter accessible to Drupal.
I cannot help with your other questions because I didn't set up any way to switch themes (only to *assign* them based on user agent). And I don't use Ngnix.
Comment #33
pavlovt commentedThanks,
this is the only working solution for me (#18) - Drupal 7, Boost 7.x.dev, Theme Key 7.x-1.5
I'm using sub domain for the mobile site and Theme key to switch the theme - when boost is active the theme is no changing when using the sub domain - when I added ?qq=1 (or whatever difference in url path) and it worked :)
Comment #34
haggins commentedNice solutions here if you want to redirect a mobile device directly to the mobile version of your site. However, my customer wants the visitors to be asked whether they want to view the mobile version or not. This should happen on every page until the visitor checks the option "Remember decision".
My idea is to do an ajax request for mobile detection and storing/retrieving session information. As I don't think thats a beautiful solution, I would welcome other suggestions.
Using Boost (and mobile tools).
edit: instead of ajaxing the server with thousands of requests I could also a script like the one from http://detectmobilebrowsers.com/ . But a solution without the need of JS would be still much cleaner...
Comment #35
fabianx commentedJFYI: This seems to work nicely together with "Context Mobile Detect":
http://drupal.org/node/1768556#comment-7097276
Comment #36
rosso69 commentedThis #20 works 70% :)
Somehow i get a directory name %{ENV:device} instead of mobile.
My cache dir looks like
%{ENV:device}
mobile
normal
Installed apache mobile filter, changed htaccess file and settings.
Any clou?
Comment #37
Anonymous (not verified) commentedProbably a default device type is not set up so %{ENV:device} got passed through, you can verify by the folder creation time cross-referenced with the apache logs to see what browser triggered it and then go back to the apache filter documentation or just set a blanket device variable to "normal" and then change it later if a mobile device is detected.
Comment #38
mandolinrick commented#20 worked for me using same site for both mobile and other devices. Thanks for the fix! Just isn't possible for me to use separate domain for mobile.
Comment #39
davidpetit commentedAs I just stated here https://drupal.org/comment/8688899#comment-8688899, I made a sandbox project months ago which permits exactly to do this: https://drupal.org/sandbox/davidpetit/2153807
It's based on http://detectmobilebrowsers.com/ for the detection in Apache. It also uses cookies (to store users choices) and get queries (to force the mobile/desktop version) and you chose a drupal theme as to display for the mobile version.
Comment #40
cparkner01 commentedI have tried implementing the solution in #20 unsuccessfully for several days now, and have a few questions to check if I am doing things right.
I am running d6 with mobile tools and boost. I have made the changes per #20 and still cannot get boost to cache by theme/per mobile device, it is not creating a mobile directory in the /cache folder. Is there something I am missing? Which mobile module is #20 meant to be used with (perhaps not mobile tools)? What Modules should I be using this with and will I need Apache mobile filter installed on the server for this to work? Any help would be greatly appreciated, as I would really like to use the mobile theme I have created from fusion_mobile. Also I do not want to have a separate mobile sub-domain which is why I have been trying to implement #20, having boost cache by device or per theme would be great.
Comment #41
Anonymous (not verified) commentedI believe that Mike's solution was to not use any other module, to use the rewrite rules to set the directory as an environment variable and to use settings.php to create the mobile folder. It looks like the rewrite rules are quite frankly "ancient" including older Nokia java browsers. Also as noted this would not flush the cache or spider it. It may be that your mobile device is not piked up by the rules. What I would do is strip the .htaccess entirely and with the standard rules change
RewriteRule .* - [E=device:normal]to
RewriteRule .* - [E=device:mobile]to see if the folder is created, later versions of the module may ignore the settings.php configuration and in which case you'd need to find "normal".
I'd also like you to reconsider your goals and aims, I don't know how to put it, but the world has moved on, a responsive theme has no need for different caches for different devices and it would almost certainly be better for maintenance and performance to use a responsive theme once and let the css handle any differing device widths etc... The modules and rewrite rules were defined way before html5 and css3 and quite frankly shunting caches is a really blunt way of handling mobile devices or tablets.
Comment #42
subir_ghosh#20 works perfectly :)
Comment #43
c-logemannIt seems the questions how to solve this situation are answered. Closing for now.