We've recently started using superfish menus on a few sites and have been very pleased with the touchscreen support provided by the sf-touchscreen plugin. It appears however that the user agent detection feature for the touchscreen support is not compatible with the Drupal page cache. This is because user agent detection is being done on the server. If a mobile user agent is detected, the javascript on the pge is altered to enable touchscreen functionality. If this page is then cached, all anonymous users get the touchscreen functionality, regardless of user-agent.

User-agent detection should happen in the browser rather than on the server. The module could pass the user agent string via javascript, which would be cached in the page cache. Then each browser would use that string to determine for itself whether to enable the touchscreen plugin.

CommentFileSizeAuthor
#1 superfish_ua_detect-1279502.patch2.96 KBonelittleant

Comments

onelittleant’s picture

StatusFileSize
new2.96 KB

Follow-up here. I went ahead and created a patch. This patch offloads user agent detection to the browser, making user agent detection work with the Drupal page cache. I'm on Windows7, so let me know if you have trouble with newlines. The patch was generated using msysgit.

mehrpadin’s picture

Hey there,

Thanks for this, will check it asap.

onelittleant’s picture

So, I submitted a patch for D7 shortly after this one. #1279760: Touchscreen user agent detection incompatible with page cache (D7) The D7 patch has one minor improvement, in that it changes strings to lowercase in the JS before making user agent comparisons. I can reroll this patch if you'd like, or just have a look at the D7 one.

mehrpadin’s picture

Hey there,

I was not able to reproduce this, perhaps you're using some caching modules? also, which version of the Superfish are you using exactly? last but not least, are you sure this is happening with D7 too?

onelittleant’s picture

Discovered this behavior using 6.x-1.8. Patch was rolled against dev at the time.

In order to reproduce this in both D7 and D6:

- Enable page caching.
- Log out.
- Visit a page with a browser with a user agent that does not use sf-touchscreen (desktop browser).
- Visit the same page with user agent that should use sf-touchscreen (mobile device). The page that was cached for the desktop browser will be delivered, including cached inline javascript, and sf-touchscreen support will not be enabled.

This is a challenge of the Drupal page cache for anonymous users. All anonymous users get the exact same content. Content can't vary according to any aspect of a session, including user-agent, unless they are logged in and the cache is being bypassed.

mehrpadin’s picture

Status: Active » Closed (fixed)