简体   繁体   English

使用Javascript生成的网站的优点/缺点

[英]Advantages / Disadvantages to websites generated with Javascript

Two good examples would be google and facebook . 两个很好的例子是googlefacebook

I have lately pondered the motivation for this approach. 我最近考虑过这种方法的动机。 My best guess would be it almost completely separates the logic between your back-end language and the markup. 我最好的猜测是它几乎完全区分了你的后端语言和标记之间的逻辑。 Building up an array to send over in JSON format seems like a tidy way to maintain code, but what other elements am I missing here? 构建一个以JSON格式发送的数组似乎是维护代码的一种整洁方式,但我在这里缺少了哪些其他元素?

What are the advantages / disadvantages to this approach, and why are such large scale companies doing it? 这种方法有哪些优点/缺点,为什么这么大规模的公司呢?

The main disadvantage is that you have some pain with content indexation of your site. 主要的缺点是您对网站的内容索引有一些痛苦。

For Google you can somewhere solve the problem by using Crawling scheme. 对于Google,您可以使用Crawling方案在某处解决问题。 Google supports crawling that allows you to index dynamically (without page reload) generated content of your page. Google支持抓取功能,允许您动态索引(无需重新加载页面)生成的网页内容。

To do this your virtual links must be addresses like so: http://yoursite.com/#!/register/ . 要做到这一点,您的虚拟链接必须是这样的地址:http: //yoursite.com/# !/ register / In this case Google requests to http://yoursite/register/ to index content of the address. 在这种情况下,Google请求http:// yoursite / register /索引地址的内容。

When clicking on virtual link there is no page reload. 单击虚拟链接时,没有页面重新加载。 You can provide this by using onclick : 您可以使用onclick提供:

<a href='http://yoursite.com/#!/register/' onclick='showRegister()'>Register</a>

Virtual advantage is that content of a page changed without reloading of the page. 虚拟优势是页面内容在不重新加载页面的情况下发生了变化。 In my practice I do not use Javascript generation to do this because I build my interface in fixed positions. 在我的实践中,我不使用Javascript生成来执行此操作,因为我在固定位置构建我的界面。 When page reloads user does not notice anything because elements of the interface appears in expected places. 当页面重新加载时,用户没有注意到任何内容,因为界面的元素出现在预期的位置。

So, my opinion that using of dynamic page generation is a big pain. 所以,我认为使用动态页面生成是一个很大的痛苦。 I think Google did it not to separate markup and backend (it's not a real problem, you can use complex structure of backend-frontend to do that) but to use advantages of convenient and nice representation for users. 我认为谷歌不是要将标记和后端分开(这不是一个真正的问题,你可以使用后端前端的复杂结构来做到这一点),而是为用户使用方便和好的表示的优点。

Advantages 好处

  • View state is kept on the client (removing load from the server) 查看状态保留在客户端上(从服务器中删除负载)
  • Partial refreshes of pages 部分刷新页面
  • Server does not need to know about HTML which leads to a Service Oriented Architecture 服务器不需要了解导致面向服务的体系结构的HTML

Disadvantages 缺点

  • Bookmarking (state in the URL) is harder to implement 书签(URL中的状态)更难实现
  • Making it searchable is still a work in progress 使其可搜索仍在进行中
  • Need a separate scheme to support non-JS users 需要一个单独的方案来支持非JS用户

I don't 100% understand your question, but I'll try my best here... 我不是100%理解你的问题,但我会在这里尽我所能......

Google and Facebook both extensively use JavaScript across all of their websites and products. Google和Facebook都在其所有网站和产品中广泛使用JavaScript。 Every major website on the web uses it. 网上的每个主要网站都使用它。

JavaScript is the technology used to modify the behavior of websites. JavaScript是用于修改网站行为的技术。
HTML => defines structure and elements HTML =>定义结构和元素

CSS => styling the elements CSS =>样式化元素

Scripting languages => dynamically generating elements and filling them with data 脚本语言=>动态生成元素并用数据填充它们

JavaScript => modifies all of the above by interacting with the DOM, responding to events, and styling elements on the fly JavaScript =>通过与DOM交互,动态响应事件和样式元素来修改上述所有内容

This is the 'approach' as you call it to every website on the web today. 这就是您今天在网络上的每个网站上所说的“方法”。 There are no alternatives to JavaScript/HTML/CSS. 没有JavaScript / HTML / CSS的替代品。 You can change the database or scripting language used, but JavaScript/HTML/CSS is a constant. 您可以更改使用的数据库或脚本语言,但JavaScript / HTML / CSS是常量。

Consider an example of a simple form validation ... 考虑一个简单的表单验证的例子......

client sends a request to a server ... the server will execute the server side code containing validation logic and in a response ...the server will send the result to the client .... 客户端向服务器发送请求...服务器将执行包含验证逻辑的服务器端代码,并在响应中...服务器将结果发送给客户端....

if the client has the capability to execute/process (that can be executed on the client side ...) the form ...(perform validation)..the client wont need send request to the server ...and wait for the server to respond to that request ... 如果客户端有能力执行/处理(可以在客户端执行...)表单...(执行验证)..客户端不需要向服务器发送请求...并等待服务器响应该请求...

我建议你看一下Google Page Speed最佳做法http://code.google.com/intl/it-IT/speed/page-speed/ ,了解制作好网页的因素是什么...由于ui和逻辑的分离,使用javascript的页面似乎很酷,但在实践中它是完全低效的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Javascript中调用函数时使用“()”的优点和缺点? - Advantages and disadvantages of using “()” while calling function in Javascript? iPhone:使用CSS / JavaScript开发的优点和缺点是什么? - iPhone: What are the Advantages and Disadvantages of Developing with CSS/Javascript? JQuery和Glow JavaScript库的优点和缺点是什么? - What are the Advantages and Disadvantages of JQuery and Glow JavaScript Libraries? 这两种JavaScript模式之间的优缺点是什么? - What are the Advantages and Disadvantages Between These Two JavaScript Patterns? JavaScript:动态(动态)创建样式元素的优缺点 - JavaScript: Advantages and disadvantages of dynamically (on fly) creating style element 直接在WebView或MapView中使用Google Maps JavaScript API?优点和缺点是什么? - Use Google Maps JavaScript API in a WebView or MapView directly?Advantages and disadvantages? 在 JavaScript 函数开始或结束时防止默认事件动作的优缺点 - Advantages and disadvantages of preventing default event action at start or end of JavaScript function 使用后端生成的Javascript或CSS有什么缺点? - What are the disadvantages of using backend generated Javascript or CSS? 与官方标准相比,将JSON数据作为text / javascript提供的优点和缺点是什么:application / json? - What are the advantages and disadvantages of serving JSON data as text/javascript compared to the official standard: application/json? 将函数传递给Deferred的构造函数的优缺点 - Advantages/Disadvantages of Passing a Function into Deferred's Constructor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM