Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when a web app generate most markup by javascript ... [closed]

I have seen a web app that generate most of a page's markup by javascript+ jquery. The server only generate a web page with just 1 DIV . The rest are done with create on client side via javascript+jquery+AJAX .

What are the pros and cons of this javascript centric approach ?

like image 745
dan_l Avatar asked Dec 27 '22 15:12

dan_l


1 Answers

Pros:

You get a lot of flexibility when your entire front-end is in javascript. Everything is generated dynamically and it's easier to load data on demand. It also makes it easier to bind elements to data, which allows them to update automatically as things change on the server (without requiring the user to reload their browser!). Check out Backbone.js or Knockout.js for interesting approaches to building heavy javascript apps.

Going this route also allows you to keep your server very light weight. Typically, the server just has to implement a simple RESTful/JSON interface. In practice, the frontend is a single static file and it makes calls to your interface. Since you're doing these calls asynchronously while the user is on the site, it can feel much faster and more like a native app (i.e. GMail)

Another nice perk is that having the client side do more work can often decrease the load on your server. The client won't even notice the extra work, since it happens so fast, but your server might appreciate the savings. You'll also potentially use less bandwidth if you're smart about your server calls.

Cons:

Some people have javascript disabled (although in practice it's a fraction of a percent of users). Also, browser cross-compatibility can be more difficult in some edge cases (but jQuery makes this much more tolerable). The biggest con is that many web crawlers won't crawl anything on your site because crawlers generally don't execute javascript. They just parse html (Google might be an exception here?).

In my experience with building web apps, any public facing content (i.e. marketing material) should be static content so that web crawlers see it. Once the user logs into the app, I like everything to be 100% client-side with RESTful calls to my server.

like image 111
Steve Avatar answered Jan 14 '23 16:01

Steve