呈现内容驱动型 Web 应用
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
渲染是指创建所需代码来创建最终用户可通过浏览器互动的页面的过程。这包括准备内容、应用逻辑和处理,以及添加任何界面元素和显示最终页面所需的其他必需组件。内容驱动型应用侧重于加载速度快、延迟时间短和渲染速度快。
服务器端渲染 (SSR)
服务器端呈现 (SSR) 是指在服务器上呈现网页,然后将完全呈现的 HTML 发送到客户端的浏览器,而不是使用 JavaScript 在客户端上呈现这些网页。当用户访问应用时,其浏览器会向服务器发送请求。应用会在服务器上处理请求(包括从数据库或外部 API 收集数据),然后呈现所请求网页的 HTML。然后,服务器会将完全呈现的网页 HTML 发送回用户的浏览器。当用户的浏览器收到 HTML 时,浏览器会加载所有必需的 JavaScript 文件。
前往 web.dev 了解 HTML。
使用 SSR 的好处包括:快速的初始加载速度、良好的搜索引擎优化 (SEO) 性能、可靠性以及良好的整体用户体验。
但是,由于性能开销以及构建和维护支持 SSR 的应用所需的开发技能,SSR 可能比客户端渲染 (CSR) 更加复杂。SSR 特别适合内容驱动的 Web 应用、电子商务平台以及任何需要良好 SEO 性能和快速初始响应速度的应用。
静态网站生成 (SSG)
静态网站生成 (SSG) 会在构建时生成静态 HTML 文件,并将其提供给用户,而无需服务器端或客户端呈现。Web 内容通常采用结构化格式(例如 Markdown、JSON 或 YAML),包括文本、图片和其他资源。静态网站生成器工具(如
Hugo 或 Jekyll)会处理内容并生成 HTML、CSS 和 JavaScript 文件。静态输出是整个网站,而这些静态文件会部署到网络服务器、CDN 或托管服务。
请访问 web.dev 详细了解 CSS 和 HTML。
由于文件是静态的,因此可以缓存,因此加载速度非常快。对于不经常更改或通过定期网站构建进行更新的 Web 应用,SSG 是一个不错的选择。它不适合具有动态互动性的 Web 应用。
客户端渲染 (CSR)
客户端呈现 (CSR) 发生在客户端的浏览器上,而不是服务器上。
Web 应用通常使用最少的 HTML 模板加载,然后使用 JavaScript 以及来自服务器或 API 的数据动态操控内容。在收到应用请求后,服务器会发送最小的 HTML 文档,其中包含呈现网页所需的基本结构和 JavaScript 代码。JavaScript 代码会在用户的浏览器中执行。然后,代码会处理提取的数据并生成内容,包括 CSS、HTML 和所有交互元素。然后,JavaScript 代码会对用户互动(例如表单提交)做出响应。
CSR 的优势包括快速网页转换和响应迅速的界面。
与 SSR 相比,基于 CSR 的 Web 应用的初始加载时间通常较长,并且可能会带来 SEO 挑战。随着 CSR 应用的不断增长,其开发和维护工作会变得越来越复杂。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003eRendering transforms code into interactive web pages, encompassing content preparation, logic application, and UI element integration for display.\u003c/p\u003e\n"],["\u003cp\u003eServer-Side Rendering (SSR) generates HTML on the server, delivering complete pages to browsers, prioritizing speed and SEO but requiring more complex implementation.\u003c/p\u003e\n"],["\u003cp\u003eStatic Site Generation (SSG) creates static HTML at build time for fast loading and caching, ideal for unchanging content but unsuitable for dynamic interactions.\u003c/p\u003e\n"],["\u003cp\u003eClient-Side Rendering (CSR) relies on browser-based JavaScript to render pages, offering responsive interfaces but potentially slower initial load times and SEO challenges.\u003c/p\u003e\n"]]],["Rendering creates code for user-interactive web pages. Server-side rendering (SSR) renders HTML on the server, sending complete pages to the browser for fast loading and good SEO. Static site generation (SSG) builds static HTML files at build time for quick delivery, ideal for infrequently updated sites. Client-side rendering (CSR) uses minimal initial HTML, with JavaScript dynamically generating content in the browser, allowing fast page transitions but often leading to slower initial load times.\n"],null,["# Rendering for Content-Driven Web Apps\n\nRendering refers to the process of creating the code needed to create a page\nthat end users can interact with through their browser. This includes preparing\nthe content, applying logic and processing and including any UI elements and\nother required components needed to display the final page. Content-driven\napplications have a focus on fast load speed, low latency and fast rendering\ntimes.\n\nServer-side rendering (SSR)\n---------------------------\n\nServer-side rendering (SSR) involves rendering web pages on the server and then\nsending the completely rendered HTML to the client's browser rather than\nrendering them on the client-side with JavaScript. When users access an\napplication, their browser sends a request to the server. The application\nprocesses the request on the server, which includes collecting data from\ndatabases or external APIs, then renders the HTML for the requested page. The\nserver then sends the fully rendered HTML of the page back to the user's\nbrowser. When the user's browser receives the HTML, the browser loads any\nrequired JavaScript files.\n\n[Learn HTML at web.dev](https://web.dev/learn/html).\n\nBenefits of using SSR include a fast initial loading speed, good search engine\noptimization (SEO) performance, reliability, and a good overall user experience.\nHowever, SSR can be more complex to implement than client-side rendering (CSR)\ndue to performance overhead and the development skill necessary to build and\nmaintain SSR-capable applications. SSR is especially beneficial for\ncontent-driven web applications, ecommerce platforms, and any application that\nrequires good SEO performance and fast initial response speeds.\n\nStatic Site Generation (SSG)\n----------------------------\n\nStatic site generation (SSG) generates static HTML files at build time and\ndelivers them to users without server-side or client-side rendering. Web content\nis authored, usually in a structured format such as Markdown, JSON, or YAML, and\nincludes text, images, and other assets. A static site generator tool, such as[Hugo](https://gohugo.io/), or\n[Jekyll](https://jekyllrb.com/), processes the content and\ngenerates HTML, CSS, and JavaScript files. The static output is the entire\nwebsite, and these static files are deployed to a web server, CDN, or hosting\nservice.\n\nLearn more about [CSS](https://web.dev/learn/css)\nand [HTML](https://web.dev/learn/html)\nat web.dev.\n\nSince the files are static, they can be cached and therefore load very quickly.\nSSG is a good option for web applications that don't change frequently or those\nthat are updated through periodic site builds. It is not a suitable choice for\nweb applications with dynamic interactivity.\n\nClient-side Rendering (CSR)\n---------------------------\n\nClient-side rendering (CSR) occurs on the client's browser, not on the server.\nWeb applications are often loaded at minimal HTML templates, and then the\ncontent is manipulated dynamically using JavaScript and data from servers or\nAPIs. After an application request, the server sends a minimal HTML document\nwith the basic structure and JavaScript code needed to render the page. The\nJavaScript code is executed in the user's browser. The code then processes the\nfetched data and generates the content, including CSS, HTML, and all interactive\nelements. The JavaScript code then responds to user interaction, such as form\nsubmission.\n\nBenefits of CSR include fast page transitions and responsive interfaces.\n[CSR-based web\napplications](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/Introduction)\noften have slow initial loading times compared to SSR, and can present SEO\nchallenges. As CSR applications grow, they can become quite complex to develop\nand maintain."]]