[Catalyst] Browser Detection?
Mike Raynham
catalyst at mikeraynham.co.uk
Sun Mar 6 15:14:10 GMT 2011
On 06/03/11 14:45, John M. Dlugosz wrote:
> On 3/6/2011 8:06 AM, Charlie Garrison garrison-at-zeta.org.au
> |Catalyst/Allow to home| wrote:
>> Good morning,
>>
>> On 6/03/11 at 5:36 AM -0600, John M. Dlugosz <wxju46gefd at snkmail.com>
>> wrote:
>>
>>> I'd like to set flags based on what that contains, like "send SVG
>>> images". Where would I put that in MyApp so it gets called some time
>>> before rendering the view?
>>
>> I do browser detection (checking) in the `auto` method (so I can
>> redirect to 'upgrade browser' page). But it could also be done in the
>> `end` method if you just want to put stuff in stash for the view. If
>> you've got a base method that all other actions chain from (which
>> seems to be current best practices) then you could put it there too.
>>
>>
>> Charlie
>>
> Ah, I see: the 'end' is the end of the controller phase and is still
> done before calling TT.
>
> My general policy is not to forbid older browsers, but to withhold the
> CSS and add a banner. So, I did that in the page-wrapping template for
> the site. I also plan to start using SVG, so a flag that tells the TT
> template to give the IMG or the OBJECT, based on whether the browser is
> on the list of those chosen to get SVG.
>
> Looking toward the future, I'm hoping that IE9 will be a sea-change. So
> as with normal programming languages, I'm thinking that a new project
> should use up-to-date features.
>
> By chaining actions, you mean how http://site.com/foo/bar/baz will have
> a base action at foo, then more action at bar, etc? I don't think my
> current project works well for that. Is the current trend to chain back
> to the root? I don't see how that adds anything over 'auto', but I'll
> re-read that section carefully.
>
>
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
It may be worth noting that browser detection is often considered to be
a bad idea. The thought being that if you want to affect content
delivery based on browser capability, then it is browser capability that
you should detect.
As far as I know, you usually need Javascript for this, as user agent
strings can be unreliable. Of course, using Javascript precludes
detection where the user has Javascript disabled.
Here's some more information for you:
http://css-tricks.com/browser-detection-is-bad/
http://www.quirksmode.org/js/detect.html
http://www.quirksmode.org/js/support.html
Depending on your needs, another approach may be to use IE conditional
comments to wrap a fake get request to your app, which your app can then
use to determine the version of IE. Something like the image tracker
method used by Piwik:
http://piwik.org/docs/tracking-api/#toc-two-tracking-method-image-tracking-or-using-the-api
More information about the Catalyst
mailing list