开发者

Advantages of All-Javascript Webpages

开发者 https://www.devze.com 2023-03-05 18:47 出处:网络
I have noticed that many big(huge) sites like Google and Facebook when looking to the page source 99% of the source is JavaScript.

I have noticed that many big(huge) sites like Google and Facebook when looking to the page source 99% of the source is JavaScript.

Does anybody know the advantages to this approach versus regular HTML+JavaScript pages?

Is it just to add some security or does it have benefits in terms of perfor开发者_StackOverflow社区mance or maintainability?


One reason why I have implemented pages in this pattern is because I wanted to have a client-agnostic server that just serves data packaged in an easily-parseable format (such as JSON) so that the same server could be used to drive a traditional webapp as well as other things such as native Android and iPhone applications without needing any special modifications to server code.

A JavaScript-heavy page allows you to work with such a setup by having the JavaScript request the required data from the server and then use it to construct an interface in HTML. Given that most of the major players have similar concerns with wanting a single server architecture to power an application across a large number of platforms, that may be a contributing factor with respect to why they have chosen to implement their webpages primarily in JavaScript.


Advantages of All-Javascript Webpages

There are many disadvantages, one being that accessibility is destroyed. Another is that you very often end up completely rewriting the client UI, which then leads to cross-browser issues and clunky performance since native browser functions are replaced with DOM equivalents.

Try any of those sites with an older or non-mainstream browser and older PC. You probably won't like the experience.

Lastly, search bots won't index your site unless they are clever enough to understand the script and data - I don't think many do.


None of those in my opinion. It's just more interactive and easier to do if you want to show differently on different screen sizes and so on. And some perfomances for some parts (I saw a thing from msdn where they were storing chunks on localstorage with JavaScript and therefore incredibly decreasing the number of http requests but it means droping browsers without JS).


I would definitely not recommend writing pages predominantly with javascript 'manually'. I think the most likely reason their pages look like this is that they are using libraries such as JSF etc. that generate javascript dynamically for them. Javascript does have the performance benefit of running directly on the client instead of needing to request the server to do the work (which implies a round trip to the server) although this is usually limited to trivial tasks that do not require access to server resources. As for maintainability though, I would say a page written with too much 'manual' javascript would be harder to maintain. For better maintainability you should include javascript in a separate js file.

0

精彩评论

暂无评论...
验证码 换一张
取 消