后端渲染html
前端angular、backbone模板引擎渲染
直接使用jquery的html,append等方法
在实现过程和效率上各有何区别?
回复内容:
泻药……好大的题……
偶懒的说怎么办……
凑合叨逼几句得了。
1、后端渲染
实现:后端拼字符串呗…… (理论上后端模板也是字符串)
好处:模板统一在后端。前端(相对)省事,不占用客户端运算资源(解析模板),只要不大改结构,文字啥的小修改后端改了就好了。
坏处:占用(部分、少部分)服务器运算资源、,response 出的数据量会(稍)大点,模板改了前端的交互和样式什么的一样得跟着联动修改。
2、前端模板
实现:看这个吧……关于模板引擎的工作方式和性能? - 前端开发 但不仅限于正则替换这一招,扫token 生成语法树,再根据语法树拼接也行,或者使用 DOM 模板,借助 DOM API 处理也行,反正招儿多了去了。
好处:不占用服务端运算资源(解析模板),模板在前端(很有可能仅部分在前端),改结构变交互都前端自己来了,改完自己调就行。不用麻烦后端再联调神马的。
坏处:占用(一部分、少部分)客户端运算资源(解析模板)。前端代码多点,毕竟包含模板代码了么。脚本是不是首次下就慢点了(看你在意不在意这个毕竟能304和CDN啥的)。可能造成前后两份模板的情况,总归要后端吐出个首屏啥的先让用户看见吧。那这部分页面模板不就是后端拼好了吐出来的么。
3、jquery的html,append等方法(包括浏览器原生相关DOM API)
实现:……这就不说了吧,不就是直接插内容或者DOM节点么。除非后端是直接吐出拼好的页面,否则不关后端是通过接口吐的html字符串还是模板数据,怎么着不都得是通过这些玩意整页面里去么。
好处:(兴许是)灵活…… 还有因为一竿子捅到底了,直接使用(前端可控的)最终API,所以除了是后端直接吐的页面外,这种方式是(相对)执行效率最高的……
坏处:各种字符串和DOM节点拼来拼去真的很烦…… 简单来说
后端渲染html 叫吐或者喷,机器人可以看到完整的呈现源码
前端模板渲染html叫填,机器人看不到完整的呈现源码 如果后端人员能力不强或对前端了解不够,尽量少用后端渲染;
如果前端人员能力不强或者前端数据交互不是很复杂,尽量少用前端模版;
如果项目不是很大,想快速实现,用jquery; 题太大,回答一点儿.
所有的渲染最终浏览都是一个html页面+js,差别就是在于后端渲染的很多都是会生成些冗余的垃圾代码(目前很对都是),前端比较好控制 都没有人提到SEO么 我觉得题主提到的这些技术可以分为两类,分类的依据在于浏览器到底做了什么事情
后端渲染HTML的情况下,浏览器会直接接收到经过服务器计算之后的呈现给用户的最终的HTML字符串,这里的计算就是服务器经过解析存放在服务器端的模板文件来完成的,在这种情况下,浏览器只进行了HTML的解析,以及通过操作系统提供的操纵显示器显示内容的系统调用在显示器上把HTML所代表的图像显示给用户。
前端渲染就是指浏览器会从后端得到一些信息,这些信息或许是适用于题主所说的angularjs的模板文件,亦或是JSON等各种数据交换格式所包装的数据,甚至是直接的合法的HTML字符串。这些形式都不重要,重要的是,将这些信息组织排列形成最终可读的HTML字符串是由浏览器来完成的,在形成了HTML字符串之后,再进行显示。
题主所提到的几个技术,我认为模板这个词语并不能用来区分这些技术的本质,模板只是一种提供给程序来解析的一种语法,换句话说,模板是用于从数据(变量)到实际的视觉表现(HTML代码)这项工作的一种实现手段,而这种手段不论在前端还是后端都有应用。
以下为本人自己的想法:
在性能上,我认为后端渲染最终会被前端渲染,因为后端渲染将所有的HTML生成集中在了一个服务器上,而前端渲染将这部分工作分发到各个终端上。
另外,对于开发而言,这样能够避免后端开发人员过多的编写HTML代码,后端开发人员只需和前端开发事先商定好数据格式,后端就只需将数据生成,用数据交换格式包装,再发送出去就可以了,这样能够使开发人员之间的分工更加明确。 其实我觉得题主的意思分成具体的情景可能是两种:
① 页面是PHP文件,是由和标签混合嵌套而成,比如WordPress模板,这类情况是前端资源的加载在服务器端就解析完成,这种方式就是后端承受的压力大;
② 页面没有任何后端代码嵌套,数据用ajax或者websocket请求,这种情况就是实现了前后端的完全分离。至于html结构,也分为用模板和动态操作DOM两种情况,模板的原理主要是靠正则匹配替换,假设整个交互过程中,html结构没有太大变化,那么模板效率相对好些,如果需要频繁动态地更新的html结构,必然要操作DOM,例如append()、html()、remove()、empty(),这种方法很灵活,但是DOM查找是件代价比较高的事,尤其如果在移动端性能就会下降。

HTML5 brings five key improvements: 1. Semantic tags improve code clarity and SEO effects; 2. Multimedia support simplifies video and audio embedding; 3. Form enhancement simplifies verification; 4. Offline and local storage improves user experience; 5. Canvas and graphics functions enhance the visualization of web pages.

The core features of HTML5 include semantic tags, multimedia support, offline storage and local storage, and form enhancement. 1. Semantic tags such as, etc. to improve code readability and SEO effect. 2. Simplify multimedia embedding with labels. 3. Offline storage and local storage such as ApplicationCache and LocalStorage support network-free operation and data storage. 4. Form enhancement introduces new input types and verification properties to simplify processing and verification.

H5 provides a variety of new features and functions, greatly enhancing the capabilities of front-end development. 1. Multimedia support: embed media through and elements, no plug-ins are required. 2. Canvas: Use elements to dynamically render 2D graphics and animations. 3. Local storage: implement persistent data storage through localStorage and sessionStorage to improve user experience.

H5 and HTML5 are different concepts: HTML5 is a version of HTML, containing new elements and APIs; H5 is a mobile application development framework based on HTML5. HTML5 parses and renders code through the browser, while H5 applications need to run containers and interact with native code through JavaScript.

Key elements of HTML5 include,,,,,, etc., which are used to build modern web pages. 1. Define the head content, 2. Used to navigate the link, 3. Represent the content of independent articles, 4. Organize the page content, 5. Display the sidebar content, 6. Define the footer, these elements enhance the structure and functionality of the web page.

There is no difference between HTML5 and H5, which is the abbreviation of HTML5. 1.HTML5 is the fifth version of HTML, which enhances the multimedia and interactive functions of web pages. 2.H5 is often used to refer to HTML5-based mobile web pages or applications, and is suitable for various mobile devices.

HTML5 is the latest version of the Hypertext Markup Language, standardized by W3C. HTML5 introduces new semantic tags, multimedia support and form enhancements, improving web structure, user experience and SEO effects. HTML5 introduces new semantic tags, such as, ,, etc., to make the web page structure clearer and the SEO effect better. HTML5 supports multimedia elements and no third-party plug-ins are required, improving user experience and loading speed. HTML5 enhances form functions and introduces new input types such as, etc., which improves user experience and form verification efficiency.

How to write clean and efficient HTML5 code? The answer is to avoid common mistakes by semanticizing tags, structured code, performance optimization and avoiding common mistakes. 1. Use semantic tags such as, etc. to improve code readability and SEO effect. 2. Keep the code structured and readable, using appropriate indentation and comments. 3. Optimize performance by reducing unnecessary tags, using CDN and compressing code. 4. Avoid common mistakes, such as the tag not closed, and ensure the validity of the code.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Linux new version
SublimeText3 Linux latest version
