Javascript – XML, XSLT and JavaScript

ajax, javascript, xml, xslt

I'm having some trouble figuring out how to make the "page load" architecture of a website.

The basic idea is, that I would use XSLT to present it but instead of doing it the classic way with the XSL tags I would do it with JavaScript. Each link should therefore refer to a JavaScript function that would change the content and menus of the page.

The reason why I want to do it this way, is having the option of letting JavaScript dynamically show each page using the data provided in the first, initial XML file instead of making a "complete" server request for the specific page, which simply has too many downsides.

The basic problem of that is, that after having searched the web for a solution to access the "underlying" XML of the document with JavaScript, I only find solutions to access external XML files.

I could of course just "print" all the XML data into a JavaScript array fully declared in the document header, but I believe this would be a very, very nasty solution. And ugly, for that matter.

My questions therefore are:

  • Is it even possible to do what I'm
    thinking of?
  • Would it be SEO-friendly to have all
    the website pages' content loaded
    initially in the XML file?

My alternative would be to dynamically load the specific page's content using AJAX on demand. However, I find it difficult to find a way that would be the least SEO-friendly. I can't imagine that a search engine would execute any JavaScript.

I'm very sorry if this is unclear, but it's really freaking me out.
Thanks in advance.

Best Solution

Is it even possible to do what I'm thinking of?

Sure.

Would it be SEO-friendly to have all the website pages' content loaded initially in the XML file?

No, it would be total insanity.

I can't imagine that a search engine would execute any JavaScript.

Well, quite. It's also pretty bad for accessibility: non-JS browsers, or browsers with a slight difference in JS implementation (eg new reserved words) that causes your script to have an error and boom! no page. And unless you provide proper navigation through hash links, usability will be terrible too.

All-JavaScript in-page content creation can be useful for raw web applications (infamously, GMail), but for a content-driven site it would be largely disastrous. You'd essentially have to build up the same pages from the client side for JS browsers and the server side for all other agents, at which point you've lost the advantage of doing it all on the client.

Probably better to do it like SO: primarily HTML-based, but with client-side progressive enhancement to do useful tasks like checking the server for updates and printing the “this question has new answers” announce.