XSLT/XML vs. JSON

From: Dan (HERMAND) 3 Nov 2010 20:19
To: af (CAER) 9 of 24

Thought about generating a load of database content to check it out?

 

As for server load, not that Teh is slow, but I don't think we get a great deal of traffic - I bet you could simulate it with relative ease. Matt, what's our bandwidth use / hits like?

From: af (CAER) 3 Nov 2010 20:21
To: Dan (HERMAND) 10 of 24
Yeah I already made a thing on my local copy to generate a 100-post thread so I can work on the pagination (well, it'll be more like how Twitter used to work, with a 'More' button that just loads and appends more posts).
From: Dan (HERMAND) 3 Nov 2010 20:23
To: af (CAER) 11 of 24
I can't remember what it was I used, but as you scrolled down to the bottom of the page it started loading the subsequent posts. That was nice.
From: af (CAER) 3 Nov 2010 20:26
To: Dan (HERMAND) 12 of 24
Yeah that's the way Twitter (and Google Reader) works now.
From: THERE IS NO GOD BUT (RENDLE) 4 Nov 2010 00:04
To: Ally 13 of 24

OK, if you're doing MVC, then you do SEO (and improve accessibility generally, btw) by using jQuery to do progressive enhancement. So, you have your page layouts and you can render those to traditional HTML, but you can also get your controller methods to return JSON if the client asks for that in the request header.

 

On the page load of the initial page, you run a jQuery function to find all the links on the pages and replace them with AJAX requests for the JSON data which you can then render client-side (take a look at the new Templates plug-in for that while you're at it).

 

Since SE spiders don't implement Javascript, they'll get the old-style traditional HTML, as will Readers for the visually impaired.

 

Easy.

From: af (CAER) 4 Nov 2010 09:21
To: THERE IS NO GOD BUT (RENDLE) 14 of 24
jQuery really is lovely, isn't it?
From: Ally 4 Nov 2010 20:12
To: af (CAER) 15 of 24
MOOTOOLS RULES
From: Ally 4 Nov 2010 20:14
To: THERE IS NO GOD BUT (RENDLE) 16 of 24

I had considered that. But loading entire pages through JSON results in the URL being wrong unless you use one of those systems that appends a # into the URL, no?

 

Still, I'll bear it in mind, cheers. I'm still keen on XSL simply because it means zero change of one of the design people having access to backend code through <% %> tags. But that might just be my paranoia kicking in.

From: af (CAER) 4 Nov 2010 21:00
To: Ally 17 of 24

Could you not just have the Javascript append "&format=json" to the request URLs, then let your request handler deal with things depending on the presence of that parameter?

 

edit: that's how I plan on doing it, so if it's not good way, let me know so I can avoid any problems :D

EDITED: 4 Nov 2010 21:00 by CAER
From: Ally 4 Nov 2010 21:03
To: af (CAER) 18 of 24

Oh yes, you could. But the original page URL wouldn't change because you'd be loading content via AJAX. To get around this, people end up using URLs like:

 

http://www.mysite.com/#category/page

 

and change the part after the # dynamically. It's not a big issue (Facebook gets away with it quite nicely) but it offends my OCD tendencies.

From: af (CAER) 4 Nov 2010 21:13
To: Ally 19 of 24
Ohh yeah I see what you mean - I'd worried about that actually, and how to get around the problem of dynamic page changes not affecting the browser's history state.
From: Ally 4 Nov 2010 21:17
To: af (CAER) 20 of 24
There are some JS plugins (I've used ReallySimpleHistory before) that handle history state and such.

It's still a pain, though.
EDITED: 4 Nov 2010 23:53 by ALLY
From: Matt 4 Nov 2010 21:33
To: af (CAER) 21 of 24
jQuery hashchange is better, seeing as you're already using JQuery.

(For your forum thing that is.)
EDITED: 4 Nov 2010 21:37 by MATT
From: af (CAER) 4 Nov 2010 21:37
To: Matt 22 of 24
Oo cheers, I'll keep that in mind!
From: Ally 4 Nov 2010 23:58
To: af (CAER) 23 of 24

It is one of the reasons I've been looking at XSLT/XML pages. The XSLT files are totally cachable, so when you're looking at similar pages of content (i.e., forum posts) you can use the template over and over again.

 

Low bandwidth! Huzzah!

From: THERE IS NO GOD BUT (RENDLE) 6 Nov 2010 09:44
To: Ally 24 of 24
Javascript's cacheable too, and if you use one of the free public CDNs for jQuery, chances are it's already cached on the client's device anyway. Microsoft's CDN even includes the templating/binding extension, which sounds ideal for what you're doing.