[thelist] [evolt] Is server-side browser-sniffing a bad idea? (was RE: js include error in IE 3)
George Dillon <> Evolt!
evolt at georgedillon.com
Thu Dec 6 05:38:49 CST 2001
I intended to send nate this reply offlist, but it reminded me of a
question which has been troubling me for a little while...
I've read recently that using server-side browser-sniffing to keep code lean
by tailoring it for each browser's quirks is NOT a good idea because of web
caches. The undesirable scenario is that a web cache stores the page
designed for WinMSIE5 (e.g.) and then delivers THAT verison when requested
by a user with MacNN4... resulting in a layout mess for that particular
user.
Is this a real issue or have I misunderstood how web caches work?
[Note: I am not talking about client browser caches but the server caches
created by some ISPs.]
TIA
George Dillon
===============================
nate wrote:
> i've run across a silly problem with IE 3. does anyone know if IE3/pc does
> or doesn't support included js files?
If your server allows you to use XSSI this 'feature' of IE3 is not a problem
and can easily be overcome. All you need to do is sniff for IE3 and if found
include it between style tags rather than call it as a linked .js a bit like
this:
<!--#if expr="($VAR_jssrc=/yes/)"
--><SCRIPT LANGUAGE="JavaScript" SRC="/path/myfile.js"
TYPE="text/javascript"></SCRIPT><!--#else
--><SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"><!--#include
virtual="/path/myfile.js" --></SCRIPT><!--#endif
-->
The sniffing part might go a bit like this (slightly pruned version of the
real code, but any suggestions to improve my sloppy code would be welcome :)
<!--#set var="VAR_browser" value="msie"
--><!--#set var="VAR_version" value="4"
--><!--#set var="VAR_jssrc" value="yes"
--><!--#if expr="($HTTP_USER_AGENT=/Mozilla.*.*/)
&& ($HTTP_USER_AGENT !=/compatible/)
&& ($HTTP_USER_AGENT !=/Spoofer/)
&& ($HTTP_USER_AGENT !=/Opera/)
&& ($HTTP_USER_AGENT !=/WebTV/)"
--><!--#set var="VAR_browser" value="nav"
--><!--#endif
--><!--#if expr="($HTTP_USER_AGENT=/Opera/)"
--><!--#set var="VAR_browser" value="opera"
--><!--#endif
--><!--#if expr="($HTTP_USER_AGENT=/AOL/)"
--><!--#set var="VAR_browser" value="aol"
--><!--#endif
--><!--#if expr="($HTTP_USER_AGENT=//1/)
|| ($HTTP_USER_AGENT=/ 1/)"
--><!--#set var="VAR_version" value="1"
--><!--#endif
--><!--#if expr="($HTTP_USER_AGENT=//2/)
|| ($HTTP_USER_AGENT=/ 2/)"
--><!--#set var="VAR_version" value="2"
--><!--#endif
--><!--#if expr="($HTTP_USER_AGENT=//3/)
|| ($HTTP_USER_AGENT=/ 3/)"
--><!--#set var="VAR_version" value="3"
--><!--#endif
--><!--#if expr="($HTTP_USER_AGENT=//5/)
|| ($HTTP_USER_AGENT=/ 5/)"
--><!--#set var="VAR_version" value="5"
--><!--#endif
--><!--#if expr="($HTTP_USER_AGENT=//6/)
|| ($HTTP_USER_AGENT=/ 6/)"
--><!--#set var="VAR_version" value="6"
--><!--#endif
--><!--#if expr="($HTTP_USER_AGENT=/Gecko/)"
--><!--#set var="VAR_browser" value="gecko"
--><!--#set var="VAR_version" value="6"
--><!--#endif
--><!--#if expr="($VAR_version=/1/)
|| ($VAR_version=/2/)
|| (($VAR_version=/3/) && ($VAR_browser=/msie/))"
--><!--#set var="VAR_jssrc" value="no"
--><!--#endif
-->
HTH
George Dillon
More information about the thelist
mailing list