The pros and cons of developing a complete Javascript UI
devblog.supportbee.com
devblog.supportbee.com
When you build one of these things, you spend most of your dev time running it locally, and as a result it's snappy. You can do things like loading a blank page for your task list, then flowing in tasks via Ajax and it will render pretty much instantly. It's so fast that you'll even consider loading those tasks one at a time.
For the rest of us, using an application like YouTrack or Flow (getflow.com) is sheer torture. View an item, hit the back button, wait 10 seconds for the list page to come back up, reload its content, and rebuild the page before your eyes before you can even start trying to scroll back to where you were.
Compare that to the old user experience where that list page would be a chunk of HTML generated at the server in 50ms and handed to you across the wire. Your browser would cache it, so the back button operation I describe above wouldn't even involve a trip to the server most of the time. Your browser would remember its previous scroll position. It was fast and it worked. It never occurred to any of us that people would decide to throw it out and replace it with something worse.
So if you're considering building one of these things, step one needs to be spinning up an EC2 box on another continent to act as your "dev" server. Latency is suddenly your number one priority in life, with your app being secondary. Please don't complain about this fact, since it's something you chose for yourself.
Thanks.
If the initial page load is a problem, you can use a CDN to distribute the javascript files. I am not sure about the scroll problem though. Thanks for pointing it out
The thing is, the more pieces of the browser that you try to replace with javascript, the more opportunities you have to get them subtly wrong. Just watch the discussion here whenever somebody submits an article using that wordpress plugin that tries to replicate an iPad's scrolling functionality inside of your iPad.
It's just barely different, but that's why it's so annoying. If it were completely different, it actually wouldn't be a problem at all. But it's not. It just feels like it's not working right.
Ever tried the new Twitter? You now have to wait 12 seconds to see the Tweets.
Why not load the page in 1 sec. without the use of Javascript and use Javascript for realtime updates? Because it's cool to use Javascript and make your page slow as hell?
Whats wrong with page-reload-apps that are lightning fast?
Maybe the hip Javascript developers don't realize a Javascript driven page needs at least 3 request (page + javascript + content) instead of 1 (page)?
* a tiny anchor HTML page with data key info
* a general purpose .js file (or small number of such)
* template HTML pages
* content (e.g. - JSON)
The tiny "anchor" page should be small (latency still hurts, of course);
The JS should be cached locally once the app has been used for the day;
The HTML templates pages should also cache;
The content must be loaded, suffering latency -- however, if the content is large, your app can display something while the content is being generated (perhaps by a big, slow, legacy data source???).
Another consideration: if all content is delivered via a REST API as JSON or (ugh) XML, there is a better chance it will be properly encoded for display. Hopefully, I can save a nice JavaScript fragment in a submission to said site, and the AJAX page construction code will simply add it to the resulting page to be displayed, rather than to be run. Hmmmm, perhaps I want my testing fixtures to fill the test database with XSS samples while I am at it, such as the newer entries in http://ha.ckers.org/xss.html (or a more recent list), and then to display that data on a few pages of manual testing.
One of the easy ways is to simply in-line your JSON model when you generate the initial page.
So essentially your webpage contains the html structure you need, followed by something like
<script>
Myapp.start( { tasks: [ { id: 1, title: 'do something' } ])
</script>
So essentially you bootstrap your application in order to avoid a large AJAX call right off the bat.With html5 features (i.e. local storage) you can just cache data client-side and sync in the background.
I.e. build a disconnected client-server application.
To reduce bandwidth and latency, I'd rather recommend using a throttling proxy such as Charles Proxy on your machine.
Now, if you go with a service oriented approach, as has Twitter and Facebook, you can build an API your JS client can talk to. One issue with this is, developing these kinds of services assumes a sort of stability, which can't be taken for granted in the earlier stages of application development.
Of course, there are frameworks that help speed this sort of thing up, but it makes it difficult to leverage libraries outside of the framework, as they're intended for single page applications. And you're still stuck with writing a client for each of your target platforms (JS/Static/Mobile Web/Mobile API).
When I first encountered Mustache, the dream of having one view rule them all tantalized me. So I started playing around with it, and have been working on an experiment I call "Marionette". It's basically the antithesis of something like SproutCore, in that the client is fairly dumb, and more or less draws the same as the server using an exposed API, and any widgets would be added on top in the form of your regular MooQuery libraries. I have a lot of work to do with the execution (history navigation is broken, for starters), but I think the overall premise has merit.
I'd wanted to polish it up a little before showing it off, but this article has inspired me to get it out the door. "Release early...", and all that.
https://github.com/bigbento/marionette https://github.com/bigbento/marionette-demo
First, are there companies other than Twitter that have made an API strategy work? In other words, are there lots of examples of companies for whom their open API has been critical to adoption?
Second, it seems like requiring the developers to develop an API means that now they have two problems: designing a UI and designing an API. But in any case, are there modern MVC web frameworks that don't make providing an API as easy as creating views for XML and JSON as well as HTML?
Third, has any website released their UI code as open source to help people code against their API? Is this a sensible way for people to learn how the API works?
Overall, I think there is something compelling about a single page, complete Javascript UI, but parts of this feel a bit like back-solving a justification. Are the better arguments all really UI-related and not backend-related?
It seems to me that the an API strategy can be very effective in making something already popular really take off. No one is going to build cool apps on top of your api unless you have users to actually leverage them. I'm always skeptical of models that depend completely on an API play.
So, I don't think Facebook really counts as an example that supports the author's argument.
I work with an exceptionally complex ext.js application (not develop, I'm just a user of it). In IE you can click a button, make a cup of tea, and come back to see it finish working. In Chrome and Firefox, there's nothing wrong with the performance of the client.
No doubt we are moving to a more dynamic client side, but I haven't seen the way forward yet.
Backbone, and others, are awesome but still don't seem like the whole solution.
Even then if you the site you are building gets a little more popular, you will have to support more platforms, like older versions of IE, and then were back at the start.
As for urls and bookmarking, HTML5 history api can help (Github source navigation)
I think most javascript frameworks make this pretty easy, I am most familiar with Backbone's Router (recently renamed from Controller)
See: http://documentcloud.github.com/backbone/#Router
In the future, the HTML5 history API should make this even simpler. People definitely do screw this up though.. I don't think the recent Gawker/Gizmodo redesign did this initially, and it seemed like that was one of the reasons people really hated it.
We've seen how well such sites are received when HN was dominated by blogs ranting about the new Gawker design.
So to fix this, you'd have to do three applications:
1) the API that you use in the JS GUI
2) The JS GUI
3) The dynamically generated HTML for JS-less browsers
Or you change the JS GUI so it requests page fragments and work with history.pushState (PJAX) allowing you to skip the API again, though, of course, then you don't have an API.
I've reasoned about this last april: http://pilif.github.com/2011/04/ajax-architecture-frameworks...
I find the 'javascript to enhance' guideline helpful to. Then sites are more likely to be functional (but not pretty) in older browsers. A good example is javascript to make menus slide, but which use CSS to make them come up.
But, of course, if you go the JS only route (which I have done for my tempalias.com fun project last year), then you also have to keep in mind that you will be duplicating model code and dealing with two separate ORM layers:
One on the server for the API itself and one on the client which gets used by the GUI controllers. Backbone can be of help there, but if you want to, say, do some validation logic already on the client without the roundtrip, then you begin duplicating logic on both server and client.
So how ever you put it, going JS only is probably more work in the end, but it's also less work than going the traditional way and then bolting on a fully-fledged API because the lack of dogfooding it will cause you trouble once you get real users for it.
Overall it's a really difficult decision to make and it's also quite final as changing the direction, again, means a lot of work.
The server would offload as many procedures to the client as possible (that is none if js is disabled, some if you don't want to expose your guts).
The server html renderers would be the exact same code in the client, the api would be a simple thin wrapper around your "protected" procedures.
You could event support ecmascript5 features on IE6, executing the js in the server.
If you are building an interactive web application that should be akin to classic desktop applications, you should really build a separate UI, just like if you were building a desktop application. If you are using a framework such as GWT, than it doesn't even have to "look" like two different applications from the developers point of view. Building a detached UI doesn't imply creating a nice public API at the same time.
On the other hand, if you are trying to create a content based site logically designed as linked pages of content, there really is no good reason to brake the classic web page layout and reinvent the wheel.
The problem, ofc, is what to do when your site is a hybrid between the two. Well, maybe a hybrid approach should apply also?
Most of the problems mentioned with the newer approach, js UI, are technical problems that must be solved (by us), not conceptual problems in the approach itself.
The hassle of building a custom UI and event strategy without a pre-packaged UI kit seems like a recipe for headaches, but that may be a function of my own limitations in Javascript. I've tried it in Backbone and in Sproutcore 2 beta 2. Both are very promising, but I found myself dealing with so many common UI use cases that I really wished for plug-and-play UI kit modules.
Also, the online community for JS frameworks so young that it's hard to find other people's solutions. For instance, I wanted to hook into devise to authenticate users and store the current_user on the client-side. I ended up making my own solution, with no guidance from google. As a self-taught developer working alone on a few projects, I always feel better when I can at least find a random gist of another solution, if for no other reason than to see if I've missed a feature of the framework in my solution. Given how incredibly useful these JS frameworks are for imposing some structure and convention, I expect the online guidance to improve drastically over the coming year.
But, this is also a pro in the same time. That way, you are forced to layer your application(s) appropriately, it is much easier to test and faster to develop (browser F5 instead of redeploy), and, as a bonus, you get nice rest API that you can expose to your clients or third-party developers.
We do believe JS UIs if done right can be very usable. I think thats why Gmail is so popular right now. I would love to discuss more with you and push a post later.
[1] https://chrome.google.com/webstore/detail/amenlkcfjlmchdpogj...