<p>Short version: What is the cleanest and most maintainable technique for consistant presentation and AJAX function across all browsers used by both web developers and web developers' end-users?</p>

<ul>
<li>IE 6, 7, 8</li>
<li>Firefox 2, 3</li>
<li>Safari</li>
<li>Google Chrome</li>
<li>Opera</li>
</ul>

<p>Long version: I wrote a <a href="http://con.appspot.com" rel="nofollow noreferrer">web app aimed at other web developers</a>. I want my app to support the major web browsers (plus Google Chrome) in both presentation and AJAX behavior.</p>

<p>I began on Firefox/Firebug, then added conditional comments for a consistent styling under IE 6 and 7.  Next, to my amazement, I discovered that jQuery does not behave identically in IE; so I <a href="http://github.com/jhs/app-engine-console/commit/4fe7741ad1856208b565eeab4260a64933929c01" rel="nofollow noreferrer">changed my Javascript to be portable on FF and IE</a> using conditionals and less pure jQuery.</p>

<p>Today, I started testing on Webkit and Google Chrome and discovered that, not only are the styles inconsistant with both FF and IE, but Javascript is not executing at all, probably due to a syntax or parse error.  I expected some CSS work, but now I have more Javascript debugging to do!  At this point, I want to step back and think before writing piles of special cases for all situations.</p>

<p>I am <b>not looking for a silver bullet, just best practices</b> to keep things as understandable and maintainable as possible.  I prefer if this works with no server-side intelligence; however if there is a advantage to, for example, check the user-agent and then return different files to different browsers, that is fine if the total comprehensibility and maintainability of the web app is lower.  Thank you all very much!</p>

[{'answer_id': 45241, 'author': 'Dhaust', 'author_id': 242, 'author_profile': 'https://Stackoverflow.com/users/242', 'pm_score': 1, 'selected': False, 'text': '<p>Just so you\'ve got one less browser to worry about, Chrome uses the same rendering engine as Safari.  So if it works in Safari, it should work exactly the same in Chrome.  </p>\n\n<p>See <a href="http://www.mattcutts.com/blog/" rel="nofollow noreferrer">this post</a> on Matt Cutts\' blog.  </p>\n\n<blockquote>\n  <p>Google Chrome uses WebKit for rendering, which is the same rendering engine as Apple’s Safari browser, so if your site is compatible with Safari it should work great in Chrome. </p>\n</blockquote>\n\n<p>Update: Looks like this is now out-dated info.  Please see Vox\'s comment on this answer.</p>\n'}, {'answer_id': 45258, 'author': 'David Crow', 'author_id': 2783, 'author_profile': 'https://Stackoverflow.com/users/2783', 'pm_score': 2, 'selected': False, 'text': '<p>For UI, check out <a href="http://extjs.com/" rel="nofollow noreferrer">Ext</a>.</p>\n\n<p>It\'s great as a standalone library, though it can also be used with jQuery, YUI, Prototype and GWT.</p>\n\n<p>Samples: <a href="http://extjs.com/deploy/dev/examples/samples.html" rel="nofollow noreferrer">http://extjs.com/deploy/dev/examples/samples.html</a></p>\n'}, {'answer_id': 45616, 'author': 'Daniel James', 'author_id': 2434, 'author_profile': 'https://Stackoverflow.com/users/2434', 'pm_score': 3, 'selected': False, 'text': '<p>Chrome is actually a little different to Safari, it uses a completely different javascript implementation and problems have been reported with both prototype and jquery. I wouldn\'t worry about it too much for now, it\'s still an early beta version of the browser and such inconsistencies will probably be treated as bugs. Here\'s the <a href="http://code.google.com/p/v8/issues/detail?id=6" rel="nofollow noreferrer">bug report</a>.</p>\n'}, {'answer_id': 679997, 'author': 'system PAUSE', 'author_id': 52963, 'author_profile': 'https://Stackoverflow.com/users/52963', 'pm_score': 5, 'selected': True, 'text': '<p>I am in a similar situation, working on a web app that is targeted at IT professionals, and required to support the same set of browsers, minus Opera.</p>\n\n<p>Some general things I\'ve learned so far:</p>\n\n<ul>\n<li>Test often, in as many of your target browsers as you can. Make sure you have time for this in your development schedule.</li>\n<li>Toolkits can get you part of the way to cross-browser support, but will eventually miss something on some browser. Plan some time for debugging and researching fixes for specific browsers.</li>\n<li>If you need something that\'s not in a toolkit and can\'t find a free code snippet, invest some time to write utility functions that encapsulate the browser-dependent behavior.</li>\n<li>Educate yourself about known browser bugs, so that you can steer your implementation around them.</li>\n</ul>\n\n<p>A few more-specific things I\'ve learned:</p>\n\n<ul>\n<li>Use conditional code based on the user-agent only as a last resort, because different generations of the "same" browser may have different features. Instead, test for standards-compliant behavior first &mdash; e.g., <code>if(node.addEventListener)...</code>, then common non-standard functions &mdash; e.g., <code>if(window.attachEvent)...</code>, and then, if you must, look at the user-agent for a specific browser type &amp; version number.</li>\n<li>Knowing when the DOM is \'ready\' for script access is different in just about every browser. A good toolkit will abstract this for you.</li>\n<li>Event handlers are different in just about every browser. A good toolkit will abstract this for you.</li>\n<li>Creating DOM elements, particularly form controls or elements with attributes, can be tricky with document.createElement and element.setAttribute. While not standard (and kinda yucky), using node.innerHTML with strings that contain bits of HTML seems to be more reliable across browser types. I have yet to find a toolkit that will let you use element.setAttribute to add a \'name\' to a form element in IE.</li>\n<li>CSS differences (and bugs) are just as important as JS differences.</li>\n<li>The \'core\' Javascript features (String, Date, RegExp, Array functions) seem to be pretty reliable and consistent across browsers, especially relative to the DOM/CSS/Window functions. There\'s some small joy in the fact that the language isn\'t entirely different on every platform. :-)</li>\n</ul>\n\n<p>I haven\'t really run into any Chrome-specific JS bugs, but it\'s always one of the first browsers I test.</p>\n\n<p>HTH</p>\n'}, {'answer_id': 680025, 'author': 'levik', 'author_id': 4465, 'author_profile': 'https://Stackoverflow.com/users/4465', 'pm_score': 2, 'selected': False, 'text': '<p>One "silver bullet" you may consider turning to is <a href="http://code.google.com/webtoolkit/" rel="nofollow noreferrer">Google Web Toolkit (GWT)</a>. </p>\n\n<p>I believe it supports all the browsers you are interested in, and gives you the ability to code your UI in a Java-compatible IDE such as Eclipse. The advantage of this is you can use IDE tools for code completion and compile-time error checking, which greatly improves development on large-scale UI projects.</p>\n\n<p>If you use GWT UI components, it will hide a lot of browser-specific nastiness from having to be dealt with, but when you compile, will create a compact, deploy file for each browser platform. This way you never download any IE-specific code if you are viewing the app in Firefox. You will also have a client-side stub generated which will load the appropriate compiled bundle of JS. To sweeten the deal, these files are cacheable, so perceived performance is generally improved for returning visitors.  </p>\n'}, {'answer_id': 685801, 'author': 'Kat', 'author_id': 47219, 'author_profile': 'https://Stackoverflow.com/users/47219', 'pm_score': 2, 'selected': False, 'text': "<p>If you're starting from a base reset or framework and have accounted for IE and it's still all freaky, you may want to recheck the following:</p>\n\n<ul>\n<li>Everything validates? CSS and HTML?</li>\n<li>Any broken links to an included file (js, css, etc?). In Chrome/Safari, if your stylesheet link is busted, all of your links might end up red. (something to do with the default 404 styling I think)</li>\n<li>Any odd requirements of your js plugins that you might be using? (does the css file have to come before the js file, like with jquery.thickbox?)</li>\n</ul>\n"}, {'answer_id': 691048, 'author': 'aleemb', 'author_id': 50475, 'author_profile': 'https://Stackoverflow.com/users/50475', 'pm_score': 2, 'selected': False, 'text': '<p>The landscape has evolved considerably to accommodate cross-browser development. <strong>jQuery</strong>, <strong>Prototype</strong> and other frameworks exist for cross-browser Javascript. <strong>CSS resets</strong> are good for starting on a common blank canvas for all browsers. <strong>BluePrint</strong> and <strong>960</strong> are both CSS frameworks to help with layouts using <strong>CSS grid layouts</strong> techniques that seems to be getting very popular these days.</p>\n\n<p>As for other CSS quirks across the different browsers, there is no holy grail here and the only option is to test you website across different browsers and use this <a href="http://css-discuss.incutio.com/" rel="nofollow noreferrer">awesome resource</a> and definitely join a mailing list to save up soem time.</p>\n\n<p>If you are working on high volume production site then you can use a service like browsercam.com in the end game to ensure the site doesn\'t break horribly in some browser.</p>\n\n<p>Lastly, don\'t try to make the site look the same in every browser. Your primary design should target IE/FF and you should be okay with reasonable compromises on others. Use the <strong><a href="http://developer.yahoo.com/yui/articles/gbs/" rel="nofollow noreferrer">graded browser chart</a></strong> to narrow in on browser support.</p>\n\n<p>As for best practices, starting using wireframes on blank paper or a service like <strong>Balsamiq mockups</strong>. I am still surprised how many developers start with an editor instead of a wireframe but then again I only switched a year back before realizing how big a time saver it is. Have clean seperation of layout (HTML), presentation (CSS) and behaviors (Javascript). There should be no styling elements in HTML, no presenation in Javascript (use <code>.addClass(\'highlight\')</code> instead of <code>.css({\'background-color\': \'red\'});</code>).</p>\n\n<p>If you are not familiar with any of the bold terms in this post, Googling them should be fruitful for your web development career and productivity.</p>\n'}, {'answer_id': 691062, 'author': 'Scott Evernden', 'author_id': 11397, 'author_profile': 'https://Stackoverflow.com/users/11397', 'pm_score': 0, 'selected': False, 'text': '<p>If your very top priority is exactly consistent presentation on all the browsers listed with no disparities, you should probably be looking at AS3 and Flex.</p>\n'}, {'answer_id': 691096, 'author': 'Cameron', 'author_id': 21475, 'author_profile': 'https://Stackoverflow.com/users/21475', 'pm_score': 0, 'selected': False, 'text': '<p>Personally, I use <a href="http://mootools.net" rel="nofollow noreferrer">Mootools</a> as a simple lightweight javascript framework. It is simple to use and supports all the browsers above (except Chrome, but that seems to work too as far as I can tell).</p>\n\n<p>Also, to ensure consistency across the browsers, I get a feature/style/behaviour/etc. to work in one browser first (usually Firefox 3 with firebug), then immediately check to make sure it works in all the other browsers (leaving IE6 for last). If it doesn\'t, I inveset the time to fix it right away, because otherwise I know I won\'t have time later (in my experience, getting things to work cross-browser takes about 50% of my dev. time ;-) )</p>\n'}, {'answer_id': 694116, 'author': 'rooney', 'author_id': 63598, 'author_profile': 'https://Stackoverflow.com/users/63598', 'pm_score': 2, 'selected': False, 'text': '<p>I\'ve found four things helpful in developing JavaScript applications: </p>\n\n<ul>\n<li>Feature detection</li>\n<li>Libraries</li>\n<li>Iterative Development using Virtualization</li>\n<li>JavaScript: The Definitive Guide, Douglas Crockford &amp; John Resig</li>\n</ul>\n\n<p><strong>Feature Detection</strong></p>\n\n<p>Use reflection to ask if the browser supports the desired feature. If you want to know what event handling a browser supports, you can if(el.addEventHandler) for W3C compliance, if(el.attachEvent) for the IE-type, and finally fall back on el.[\'onSomeEvent\']. </p>\n\n<p><em>ONE BIG BUT!</em></p>\n\n<p>Browsers sometimes lie about what features they support. I can\'t remember, but I ran into an issues where Firefox implemented a DOM feature, but would return false if you tested for that feature!</p>\n\n<p><strong>Libraries</strong></p>\n\n<p>Since you\'re already working with jQuery, I\'ll save the explanation. But if you\'re running into problems you may want to consider YUI for it\'s wonderful cross-browser compatibility. They even work together.</p>\n\n<p><strong>Iterative Development with Virtualization</strong> </p>\n\n<p>Perhaps my best advice: Run all your test environment\'s at once. Get a Linux distro, Compiz Fusion and a bunch of RAM. Download a copy of either VMWare\'s VMWare Server or Sun\'s Virtual Box and install a few operating systems.  Get images for Windows XP, Windows Vista and Mac OS X.</p>\n\n<p>The basic idea is this: Compiz Fusion gives you 4 Desktops mapped onto a Cube. 1 of these desktops is your Linux computer, the next your Virtutual Windows XP box, the one after that Vista, the last Mac OS X. After writing some code, you alt-tab into virtual computer and check out your work. Plus it looks awesome.</p>\n\n<p><strong>JavaScript: The Definitive Guide, Douglas Crockford &amp; John Resig</strong></p>\n\n<p>These three sources provide most of my information for JavaScript development. The Definitive guide is perhaps the best reference book for JavaScript. </p>\n\n<p>Douglas Crockford is a JavaScript guru (I hate the word) at Yahoo. Lookup his series "Douglas Crockford Theory of the DOM", "Douglas Crockford Advanced JavaScript", "Douglas Crockford Theory of the Dom", and ""Douglas Crockford The Good Parts" on Yahoo! Videos. </p>\n\n<p>John Resig (as you know) wrote jQuery. His website at ejohn.org contains a wealth of JavaScript information, and if you dig around on Google you\'ll find he\'s given a number of presentations on defensive JavaScript techniques.</p>\n\n<p>... Good luck!</p>\n'}, {'answer_id': 694314, 'author': 'VoxPelli', 'author_id': 20667, 'author_profile': 'https://Stackoverflow.com/users/20667', 'pm_score': 0, 'selected': False, 'text': '<p>Validating your javascript with a "good parts" + browser on <a href="http://jslint.com/" rel="nofollow noreferrer">JsLint.com</a> makes it less likely to have JavaScripts behaving differently in FF, Safari etc.</p>\n\n<p>Otherwise - using standards and validating your code as well as building on existing techniques like jQuery should make your site behave the same in all browsers except IE - and there\'s no magic recipe for IE - it\'s just bugs everywhere...</p>\n'}]
['https://Stackoverflow.com/questions/45239', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2938/']