Changing a server centric site to a more JS centric one [closed]

First of all, I’m not really a Javascript guy, but more towards PHP.
However, I want to move to the next level, that is taking load off the server and let the client do the processing. Hopefully to be a more JS guy.

My first thought is to request of data off the server, and it just returns key-values which the client will generate the HTML and puck in the values.

There are 3 problems generally:

  1. I find it so much easier to generate the HTML in PHP cause data exchange between the server and HTML is fluid. Unlike returning data in JSON, which I then have to select the DOM that I want, and put in the values eg. $('.personRecord').html(data['name']).
    I also find looping through arrays and generating HTML easier than JS?

  2. I find myself using so much of jQuery selector to select the element I’m interested to manipulate and I’m not sure if that’s the correct practice (going forward to be a JS ninja). But I’m doing it cause it sure saves lots of characters.

  3. In order to select the elements easily, I tend to give them unique class names as identifier. Again, I’m not sure if that’s what a JS Ninja will do.

Going forward (web trend), I would like to know if I should try to put more work to JS?
Also, any ideas or thoughts on how I can overcome my 3 problems stated above?
Is it a sin to return formatted HTML as part of a JSON value? Or should HTML be generated in JS and only read values off the returned JSON when it needs?

Putting frameworks aside (I know there’s Backbone, Angular, Can.JS and many more) does anyone really do raw JS scripting? I mean, it is possible but seems extremely wordy.

Lastly, please advice how one would convert a server centric site to a JS centric one?

If what I wrote doesn’t make any sense, hopefully you can point some JS centric sites, and explain what approach they are using as an example. Sites that are full featured (say..maybe facebook, twitter, stackoverflow) and not just a TODO web app.

  1. jQuery is a fantastic DOM manipulation tool. What I have found though is that it is helpful to pair it with a good JavaScript templating tool (Knockout.js is one of my favorites because of the declarative data binding-like workflow it uses) precisely to do as little low-level manipulation as is possible. That said, jQuery has fantastic array looping with .each().

  2. The selector is the correct practice for retrieving DOM bits to manipulate. However, I would refer back to #1 for how to avoid doing repetitive manipulations.

  3. CSS classes should be applied to groups or things that may potentially become groups. If you really need to refer to an item directly, use an ID. It is typically preferred to group things with classes and seldom think in terms of manipulating some precise element.

Raw JavaScript (without even jQuery, Prototype JS or MooTools) can be written and can be used to manipulate the DOM. This is seldom done in practice because of the DOM implementation incompatibilities that a good framework will hide for you. If you write raw JavaScript you will quickly find that you are spending a good deal of valuable development time rediscoving oddball JavaScript/DOM incompatibilities.

As for how to perform such a conversion, there are two angles to consider: project management and technological. From the first perspective, you probably do not want to do some wholesale conversion. Rather, convert individual pieces as you fix bugs or augment their functionality.

The question lacks enough detail to provide a good technical answer. Moving towards an MVC-like architecture might be helpful. I have found web services, even very small ones, extremely helpful as they allow me to serve up fairly “dumb” pages (even if they are presented by something less-than-dumb like ASP.NET) and have the JS call off to the service to fill in data and perform operations.

Finally, you may want to step back and ask yourself why you are trying to make this transition. Better performance? Better user experience? What problem does it solve? There may be other solutions to your immediate problem.

Bear in mind that client-side scripting is no panacea. There are trade-offs. You need to be even more careful in your handling of data scrubbing and validation (which you should be doing anyway) and ensure that both your client and server side code can gracefully recover from errors presented by the other.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật