简体   繁体   English

PUG vs HTML,在Node.JS中渲染数据到视图页面哪个更好(express)

[英]PUG vs HTML, which one is better to render data to the view page in Node.JS (express)

I am new in Node.JS stack.我是 Node.JS 堆栈的新手。 I saw a big number of developers are using pug template engine (Express JS) instead of regular HTML.我看到大量开发人员正在使用 pug 模板引擎 (Express JS) 而不是常规的 HTML。 If anyone of you have used pug can you please tell me the major benefits of using pug over HTML view technology?如果你们中有人使用过 pug,能否请您告诉我使用 pug 相对于 HTML 视图技术的主要好处?

First, let's discuss the Pug framework.首先,让我们讨论 Pug 框架。 Pug framework is a highly flexible framework which supports the generation of HTML content dynamically for almost any sort of data. Pug 框架是一个高度灵活的框架,它支持为几乎任何类型的数据动态生成 HTML 内容。 You can write the Pug template to create -您可以编写 Pug 模板来创建 -

User Profiles, List of store items, Templated HTML documents, Conditional blocks in the web pages用户配置文件、商店商品列表、模板化 HTML 文档、网页中的条件块

We can render and create the conditional blocks and iterative structures to produce the dynamic HTML web content instead of hardcoding everything.我们可以渲染和创建条件块和迭代结构来生成动态 HTML Web 内容,而不是对所有内容进行硬编码。

Node.js runtime supports Pug templates by default ㅡ the template engine is Jade by default, however, Jade has been renamed to Pug. Node.js 运行时默认支持 Pug 模板 ㅡ 模板引擎默认为 Jade,但 Jade 已重命名为 Pug。 You can continue using Jade engine, but it is recommended to use Pug templates.您可以继续使用 Jade 引擎,但建议使用 Pug 模板。 Pug templated files are written as below. Pug 模板文件如下编写。

 doctype html  
html  
    head  
        title My Page  
    body  
        h1 Heading  
        p My paragraph here.  

This will get translated to the following HTML content on demand.这将根据需要转换为以下 HTML 内容。

<html>  
   <head>  
      <title>My Page</title>  
   </head>  
   <body>  
      <h1>Heading</h1>  
      <p>My paragraph here.</p>  
   </body>  
</html>  

Fast answer: HTML.快速回答:HTML。

Why?为什么? Because it is processed only by the browser, so you are removing one layer of your stack (compiling PUG).因为它仅由浏览器处理,所以您正在删除堆栈的一层(编译 PUG)。 It will make your application somewhat lighter.它将使您的应用程序更轻一些。

But PUG is an awesome tool.但是 PUG 是一个很棒的工具。 It offers nice maintainability for your code and a strict code style.它为您的代码提供了良好的可维护性和严格的代码风格。 It is useful when working with more people and it feels great.与更多人一起工作时很有用,感觉很棒。

Also, PUG increases my code efficiency by 20% in SublimeText.此外,PUG 将我在 SublimeText 中的代码效率提高了 20%。

HTML is client side rendering. HTML 是客户端渲染。 PUG is server side rendering. PUG 是服务器端渲染。 When you use SPA with HTML the whole shit has to be loaded with PUG only the page has to be rendered.当您将 SPA 与 HTML 一起使用时,整个狗屎都必须用 PUG 加载,只有页面必须呈现。 So it depends on what you want.所以这取决于你想要什么。 With SPA after the side is loaded only data is transfered from server, no HTML pages.使用 SPA 在侧加载后仅从服务器传输数据,没有 HTML 页面。 Big websites still use server site rendering.大网站仍然使用服务器站点渲染。 Geeks like Angular etc. to do client site rendering. Geeks 喜欢 Angular 等做客户端站点渲染。

It is not accurate to say that one language is "better" than the other in general.总的来说,说一种语言比另一种语言“更好”是不准确的。 Both PUG and HTML can be used to render data to the view page in a Node.JS (Express) application, and the choice of which one to use will depend on your specific needs and preferences. PUG 和 HTML 均可用于在 Node.JS (Express) 应用程序中将数据呈现到视图页面,选择使用哪一种取决于您的具体需求和偏好。

PUG is a template engine that is designed to be easy to read and write, with a focus on simplicity and expressiveness, while HTML is the standard markup language for creating web pages. PUG 是一种模板引擎,旨在易于阅读和编写,侧重于简单性和表现力,而 HTML 是创建网页的标准标记语言。 Both languages have their own unique features and syntax, and either one can be a good choice depending on the requirements of your project.两种语言都有自己独特的特性和语法,根据项目的要求,任何一种都是不错的选择。

For full article refer to https://www.ubercompute.com/blog/benefits-of-using-pug-template-over-traditional-html/有关完整文章,请参阅https://www.ubercompute.com/blog/benefits-of-using-pug-template-over-traditional-html/

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM