# Web 应用

Web 应用是一种运行在网页浏览器中的应用软件，其用户界面以 HTML、CSS 和 [JavaScript](https://www.edgepedia.org/zh/javascript) 形式交付，数据和业务逻辑通常由服务器通过 HTTP 提供。静态网站对每次请求都返回相同的硬编码内容，Web 应用则不同，它动态生成响应，根据用户、请求以及数据库中保存的数据来定制内容。<sup>[1](https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Server-side/First_steps/Introduction)</sup>

| 关键事实 | 详情 |
|---|---|
| 核心架构 | 浏览器向 Web 服务器发送 HTTP 请求；对动态资源的请求被转发到服务器端代码（即 Web 应用），后者查询数据库并返回生成的 HTML 和状态码（如 200）<sup>[2](https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Server-side/First_steps/Client-Server_overview)</sup> |
| 客户端技术栈 | HTML、CSS 和 JavaScript 在浏览器内运行，对底层操作系统的访问权限很少甚至没有，包括受限的文件系统访问<sup>[1](https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Server-side/First_steps/Introduction)</sup> |
| 可用性得分 | 在一项 2026 年的比较研究中，原生移动应用在系统可用性量表上得分 83.2（优秀），渐进式 Web 应用得分 76.5（良好）<sup>[3](https://ijcope.org/article/comparative-performance-and-user-experience-analysis-of-progressive-web-and-native-mobile-applications/)</sup> |
| 能耗与资源 | 一项 2023 年针对 10 个 Android 互联网内容平台的研究发现，原生应用的能耗显著低于对应的 Web 应用（大效应量），且 Web 应用占用更多 CPU 和内存<sup>[4](https://arxiv.org/abs/2308.16734)</sup> |
| WebAssembly 差距 | 在完整的 SPEC CPU 测试套件中，编译为 WebAssembly 的应用平均比原生代码慢 45%（Firefox）至 55%（Chrome），峰值减速分别为 2.08 倍和 2.5 倍<sup>[5](https://arxiv.org/abs/1901.09056)</sup> |
| 安全模型 | 浏览器强制执行的安全措施是机会性的：应用无法验证浏览器是否遵循其指引，因此 HTTP 安全头被视为额外的加固手段<sup>[6](https://top10proactive.owasp.org/the-top-10/c8-leverage-browser-security-features/)</sup> |
| PWA 可安装性 | Chrome 仅对满足核心渐进式 Web 应用标准的应用启用安装功能，包括通过服务工作线程实现离线支持<sup>[7](https://developer.chrome.com/blog/improved-pwa-offline-detection/)</sup> |

## Web 应用的工作原理

浏览器使用超文本传输协议（HTTP）与 Web 服务器通信。请求携带标识目标资源的 URL、定义操作的方法（如 GET 用于获取、POST 用于创建），以及 URL 参数、POST 正文或 Cookie 中的附加数据。服务器处理请求并返回带有状态行的 HTTP 响应，如表示成功的“HTTP/1.1 200 OK”。<sup>[1](https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Server-side/First_steps/Introduction)</sup>

在动态网站中，Web 服务器检测到请求是动态的，将其转发给 Web 应用；Web 应用读取 URL，从数据库检索所需数据，填充 HTML 模板中的占位符，并返回生成的页面。浏览器随后渲染 HTML，并对页面引用的 CSS、JavaScript 和图像文件发出单独请求。<sup>[2](https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Server-side/First_steps/Client-Server_overview)</sup> 客户端代码在浏览器中运行，对操作系统几乎或完全没有访问权限；相比之下，服务器端代码可以为单个用户定制内容、存储偏好设置并发送通知。<sup>[1](https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Server-side/First_steps/Introduction)</sup>

## 从文档到应用

Web 最初是一个文档系统。[蒂姆·伯纳斯-李](https://www.edgepedia.org/zh/tim-berners-lee)（Tim Berners-Lee）于 1990 年 10 月编写了第一个服务器“httpd”和第一个浏览器编辑器“WorldWideWeb”，以及第一版 HTML；欧洲核子研究中心（CERN）于 1993 年 4 月 30 日将 [WorldWideWeb](https://www.edgepedia.org/zh/worldwideweb) 源代码发布到公有领域，而 1993 年 12 月为 Macintosh 和 Windows 发布的 NCSA Mosaic 浏览器使 Web 迅速传播开来。<sup>[8](https://www.w3.org/wiki/The_history_of_the_Web)</sup>

三项发展将页面变成了应用。第一，最早在微软 Internet Explorer 5 中发布的 [XMLHttpRequest](https://www.edgepedia.org/zh/xmlhttprequest) 支持，使异步脚本（Ajax）成为可能，赋予浏览器应用类似桌面软件的行为。<sup>[9](https://www.w3.org/html/wg/wiki/History)</sup> 第二，随着 JavaScript 默认启用，单页 Web 应用兴起，大量使用客户端 JavaScript，按需加载内容而非请求完整页面。<sup>[10](https://learn.microsoft.com/en-us/archive/msdn-magazine/2012/august/building-html5-applications-a-history-api-lesson)</sup> 单页应用完全存在于单个 HTML 页面中，将服务器缩减为数据源，由客户端处理应用其余的关注点。<sup>[11](https://local.cis.strath.ac.uk/wp/extras/msctheses/papers/strath_cis_publication_2697.pdf)</sup>

第三，状态管理需要正式支持。早期的 Ajax 应用通过哈希片段和井号叹号片段（如 twitter.com/#!replies）来修改 URL，使后退按钮和搜索引擎继续工作。HTML5 History API 取代了这些技巧：`pushState` 和 `replaceState` 让应用将状态数据和真实 URL 推入会话历史栈，`onpopstate` 事件在用户后退时恢复该状态，从而使脚本密集的应用能够保持浏览器的 URL 和导航基础功能完好。<sup>[10](https://learn.microsoft.com/en-us/archive/msdn-magazine/2012/august/building-html5-applications-a-history-api-lesson)</sup> HTML5 还增加了客户端存储规范，如 [IndexedDB](https://www.edgepedia.org/zh/indexeddb) 和 Local Storage。<sup>[10](https://learn.microsoft.com/en-us/archive/msdn-magazine/2012/august/building-html5-applications-a-history-api-lesson)</sup>

## 渐进式 Web 应用与原生对比

渐进式 Web 应用（PWA）运用 Web 技术构建可安装的移动端和桌面端应用。Web 应用清单是一个 JSON 文件，定义 PWA 作为已安装应用应如何被对待，包括其外观和交互体验以及在操作系统内的基本行为。<sup>[12](https://web.dev/learn/pwa/)</sup> Chrome 仅对满足核心可安装性标准的应用启用安装功能，包括离线支持；从 Chrome 89 起，浏览器可以通过服务工作线程运行模拟的离线请求以检查实际离线行为，不过目前只要服务工作线程具有 `fetch` 事件处理器，可安装性检查即可通过。<sup>[7](https://developer.chrome.com/blog/improved-pwa-offline-detection/)</sup>

比较研究一致发现存在权衡。一项 2026 年使用真实案例（星巴克 PWA、Twitter Lite 和一款原生 Android 应用）的研究得出结论：原生应用在性能和用户体验方面更优，而 PWA 开发成本更低、维护更简单；原生应用在[系统可用性量表](https://www.edgepedia.org/zh/system-usability-scale)上得分 83.2，PWA 为 76.5。<sup>[3](https://ijcope.org/article/comparative-performance-and-user-experience-analysis-of-progressive-web-and-native-mobile-applications/)</sup> 一项混合方法研究在速度、导航、离线访问、存储空间和整体满意度方面对两者进行比较，调查了 100 名参与者，并使用随机森林模型预测用户留存和体验，达到 80% 的准确率，同时还用 Google Lighthouse 评估了 PWA 和原生应用原型。<sup>[13](https://doi.org/10.9734/jerr/2026/v28i41871)</sup>

资源差距是可测量的。在 2023 年针对 5 个类别 10 个互联网内容平台的 Android 研究中，原生应用能耗显著更低（大效应量），Web 应用占用更多 CPU 和内存，网络流量方面原生应用略占优势（小效应量）；帧时间未显示出决定性差异。<sup>[4](https://arxiv.org/abs/2308.16734)</sup> PWA 的覆盖范围还受其容器限制：它无法访问其所运行的浏览器未暴露的设备或平台功能。<sup>[14](https://link.springer.com/article/10.1007/s10664-020-09827-6)</sup>

## 性能技术

[WebAssembly](https://www.edgepedia.org/zh/webassembly) 是一种低级字节码，设计为 C 和 C++ 等语言的编译目标，旨在达到与原生代码相当的性能。其核心规范于 2019 年 12 月 5 日成为 W3C 推荐标准（Wasm 1.0），Wasm 2.0 的 W3C 候选推荐草案日期为 2025 年 6 月 16 日，WASI API 定义了在 Web 之外运行 WebAssembly 的模块化系统接口。<sup>[15](https://webassembly.org/specs/)</sup> 在完整的 [SPEC CPU](https://www.edgepedia.org/zh/spec-cpu) 套件而非小型计算内核上测量，差距仍然很大：WebAssembly 应用在 Firefox 中平均比原生代码慢 45%，在 Chrome 中慢 55%，峰值减速分别为 2.08 倍和 2.5 倍，部分原因是缺少优化和代码生成问题，部分原因是平台本身。<sup>[5](https://arxiv.org/abs/1901.09056)</sup>

跨平台框架占据 Web 与原生之间的中间地带。一项针对 Android 应用的实证研究发现，跨平台框架可能导致性能低于原生开发；一项 2026 年对同一植物管理应用的五种实现（原生 iOS、原生 Android、Flutter、React Native 和 [Kotlin Multiplatform](https://www.edgepedia.org/zh/kotlin-multiplatform)）的比较发现，原生在两种操作系统上均录得最低的非 UI 客户端时间，Kotlin Multiplatform 是最接近的跨平台实现；没有一种方法具有普遍优势。<sup>[14](https://link.springer.com/article/10.1007/s10664-020-09827-6)</sup><sup> • </sup><sup>[16](https://arxiv.org/abs/2609.21544)</sup>

## 安全

Web 应用面临独特的安全模型，因为它们部分运行在开发者无法控制的浏览器中。OWASP Top 10 是 Web 应用安全风险目录，由 OWASP 基金会首次发布，该基金会是一家通过开源项目改善软件安全的非营利组织，该目录仍是该领域的参考风险清单，最新版本为 2025 年版。<sup>[17](https://owasp.org/www-project-top-ten/)</sup>

应用通过 HTTP 头和 HTML 标签指示浏览器执行保护，但这是机会性的：应用无法验证浏览器是否遵循指引，因此这些措施是额外的加固而非保证。重复指令的行为因头而异：重复的 X-Frame-Options 头会使其保护失效，而重复的 Content-Security-Policy 头会产生更严格的策略。基于头的防御可缓解跨站脚本、[跨站请求伪造](https://www.edgepedia.org/zh/cross-site-request-forgery)、点击劫持、会话劫持以及麦克风和摄像头等硬件访问的滥用。<sup>[6](https://top10proactive.owasp.org/the-top-10/c8-leverage-browser-security-features/)</sup>

会话状态是一个核心关注点。HTTP 提供多种机制来维持会话状态，包括 Cookie、URL 参数、隐藏表单字段和专有头；Cookie 因支持令牌过期和使用限制而更受青睐。`Secure` 属性使会话 ID 不经过未加密连接，`HttpOnly` 属性阻止脚本读取 Cookie，保护其免遭跨站脚本窃取。<sup>[18](https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html)</sup> OWASP 应用安全验证标准要求，例如，每个 HTTP 响应都必须设置 Content-Security-Policy 的 `frame-ancestors` 指令，使应用默认无法被嵌入。<sup>[19](https://github.com/OWASP/ASVS/blob/master/5.0/en/0x12-V3-Web-Frontend-Security.md)</sup>

## References

1. [Introduction to the server side, MDN Web Docs](https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Server-side/First_steps/Introduction)
2. [Client-server overview, MDN Web Docs](https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Server-side/First_steps/Client-Server_overview)
3. [Hussain, S. & Bhalla, A. (2026). Comparative Performance and User Experience Analysis of Progressive Web and Native Mobile Applications. IJCOPE 2(4)](https://ijcope.org/article/comparative-performance-and-user-experience-analysis-of-progressive-web-and-native-mobile-applications/)
4. [Horn, R. et al. (2023). Native vs Web Apps: Comparing the Energy Consumption and Performance of Android Apps and their Web Counterparts. arXiv](https://arxiv.org/abs/2308.16734)
5. [Jangda, A. et al. (2019). Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code. arXiv](https://arxiv.org/abs/1901.09056)
6. [OWASP Top 10 Proactive Controls, C8: Leverage Browser Security Features](https://top10proactive.owasp.org/the-top-10/c8-leverage-browser-security-features/)
7. [Improving Progressive Web App offline support detection, Chrome for Developers blog](https://developer.chrome.com/blog/improved-pwa-offline-detection/)
8. [The history of the Web, W3C Wiki](https://www.w3.org/wiki/The_history_of_the_Web)
9. [History, HTML WG Wiki, W3C](https://www.w3.org/html/wg/wiki/History)
10. [Sell, C. (2012). Building HTML5 Applications - A History (API) Lesson. MSDN Magazine](https://learn.microsoft.com/en-us/archive/msdn-magazine/2012/august/building-html5-applications-a-history-api-lesson)
11. [Single Page Applications, University of Strathclyde MSc thesis](https://local.cis.strath.ac.uk/wp/extras/msctheses/papers/strath_cis_publication_2697.pdf)
12. [Learn PWA, web.dev](https://web.dev/learn/pwa/)
13. [Wagh, S. et al. (2026). User Experience Comparison of Progressive Web Apps and Native Mobile Applications: A Mixed-methods Approach. Journal of Engineering Research and Reports 28(4)](https://doi.org/10.9734/jerr/2026/v28i41871)
14. [Empirical investigation of performance overhead in cross-platform mobile development frameworks. Empirical Software Engineering](https://link.springer.com/article/10.1007/s10664-020-09827-6)
15. [Specifications, WebAssembly](https://webassembly.org/specs/)
16. [Ilovan, A. (2026). Cross-Platform vs Native Mobile Development: An Empirical Study of Software Quality Trade-offs. arXiv](https://arxiv.org/abs/2609.21544)
17. [OWASP Top Ten, OWASP Foundation](https://owasp.org/www-project-top-ten/)
18. [Session Management Cheat Sheet, OWASP Cheat Sheet Series](https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html)
19. [OWASP Application Security Verification Standard 5.0, V3 Web Frontend Security](https://github.com/OWASP/ASVS/blob/master/5.0/en/0x12-V3-Web-Frontend-Security.md)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Application software by domain

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/web-application

English original: https://www.edgepedia.org/web-application
