简体   繁体   中英

XML, XSLT and JavaScript

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.

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.

maybe the following scenario works for you:

  1. a browser requests your xml file.

  2. once loaded, the xslt associated with the xml file is executed. result: your initial html is outputted together with a script tag.

  3. in the javascript, an ajax call to the current location is made to get the "underlying" xml-dom. from then on, your javascript manages all the xml-processing.

  4. you made sure that in step 3, the xml is not loaded from the server again but is taken from the browser cache.

that's it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM