|
||
| Inside Technique : Backend Browser Detection : Client vs. Server There is no hard and fast rule to determine where you should do your detection. In many cases, client-side detection is used exclusively because your ISP does not allow user-defined server-side scripts to be executed. Below we discuss a few guidelines and tips: Provide alternate UI at the serverIf you visit InsideDHTML with a different browser, you will receive the same content organized in a user interface specifically designed for your client capabilities. The user interface is generated dynamically when you request the page. Since the different interfaces use very different HTML, trying to do this negotiation on the client would be a very difficult if not impossible task. I would need to understand and code around various browser issues, the page would be much larger as it will contain code for all browsers, and maintaining the page would become much more difficult. Use Standard HTML on the clientDon't write server scripts where there are already standard client-side solutions. For example, to provide a message to browsers that do not support scripting, use the NOSCRIPT element, rather than server-side code. Also, it is possible for your visitor's to disable scripting which can't be detected by the server. Don't mix server and client scriptsDo not use ASP on the server to write into script blocks unless you are providing
a completely alternative script block. Otherwise, your code quickly becomes unreadable and possibly unmaintainable.
Also, your code is now dynamically generated making debugging a much more difficult taks.
Below is a very simple example that hopefully demonstrates how this becomes confusing quickly:
Use Response.write() for one-linersIf you are doing simple conditional on the server that is outputting one or two lines based on the client, avoid writing code as follows:
You can optimize the above by writing the contents into the file using Response.write(), the server
equivalent to the client's document.write() method. This is to minimize the fragmentation
of your scripts in the document. Remember, server-side scripts require more processing power than
just sending an HTML file to the client, and the more script blocks you define the slower the page may get.
Therefore, you would rewrite the above script in a single block as follows:
ConclusionBackend browser detection is the basis for our template model. In our next backend article, we will explain how we use a standard data structure to define our inside techniques user interface. The ad bar, navigation panels, related pages, and page list are all dynamically generated based on this data structure, while the article's content is almost always statically shared. Page 1:Backend Browser Detection © 1997-2000 InsideDHTML.com, LLC. All rights reserved. |