Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- How to Master JavaScript


JAB_Creations - 4:28 pm on Oct 21, 2010 (gmt 0)


1.) It only takes a little PHP and basic understanding of headers to get XHTML to work in all browsers and degrade to regular HTML for IE8 and older...

<?php
if (isset($_SERVER['HTTP_ACCEPT']))
{
$p = explode('Validator',$_SERVER['HTTP_USER_AGENT']);

if (count($p)>1) {$mime = 'application/xhtml+xml';}
else {$mime = 'text/html';}
}
header('content-type: '.$header->mime.'; charset=utf-8');
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
?>


2.) document.write does not work with XHTML and if you use it then you cut yourself off from using XHTML easily as well as being stuck in the position of having junk code.

3.) No, innerHTML is horribly unreliable and does not correctly process things in to the DOM which makes scripting with AJAX loaded content a 50/50 and I only prefer 100% chance of things working in normal circumstances. Stick to using importNode and other node related methods. I don't see why anyone who values standards would promote the use of an unreliable proprietary Microsoft method? That or maybe you've been lucky to have it work well enough in your given situations though I really stress the browsers out so it probably comes down to the context of what we're working on.

26KB is not small, that's over six seconds on dial-up. Additionally last night I was browsing this forum and saw numerous jQuery related threads. When you get in to real JavaScript you'll get sick of seeing jQuery as the quick and easy solution. Easy is never the correct solution when you're doing mission critical.

Actually yes, WordPress is a perfect example of where jQuery fails pretty hard. I dealt with a client who had a plug-in and a theme and wanted them both. jQuery was rooted deeply in to both and I ended up refusing the work because the code was a total utter nightmare. I would like to stress that I can and do reject work as I have to prioritize my time, I refuse to work with junk code as I work with clients and am building my own business; I don't have time to deal with code that can't be used reliably once much less not used over and over again. Plus it refused to work cross-browser because of two instances and the code to override one instance didn't resolve jQuery's bugs. Yes, DHTML animations worked in IE and Opera though not Firefox and Safari which leads me to think jQuery isn't intelligent enough to test for standards compliant methods first as Opera does support some proprietary Microsoft code which in an of itself means that jQuery will perform worse on IE9 then it does on IE8 in example. I could go on and on and on, please don't tempt me. ;)

I'm okay with disagreeing with Fotiman and most other people on friendly terms. If you're used to coding one way then that's fine however I have found my approach to things to save enormous amounts of time. In example I've seen people (plural) spend hours tracking down missing quotes that only broke one browser; if I'm missing a quote when I reload the page it breaks and I get an error message telling me exactly where and what the problem is so it ends up being fixed in seconds. Most people don't code as cleanly as I do so imagine what you could do with dozens or even hundreds of hours of your life given back to you? :)

The approach with JavaScript I have taken has also made Version 2.9 of my site a total speed demon. I have a lot of features and functionality while at the same time the initial page load is under 10 seconds on a 36K modem (4,500 bytes a second) and every page load (except for my gallery) only takes 2-3 seconds on dial-up tops. It's sort of like you have to be at the top of a mountain to understand what standing at the top of a mountain is like. Not to say that Fotiman doesn't know what he's talking about because he's helped me numerous times on here, it's just our personal preferences when it comes to code differ and that's okay if at the end of the day what your clients or boss needs if finished. :)

- John


Thread source:: http://www.webmasterworld.com/javascript/4216573.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com