浏览器兼容性
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在构建内容驱动型 Web 应用时,请务必考虑受众群体正在使用哪些浏览器。有些浏览器可能使用不支持最新功能的旧版浏览器,而另一些则可能使用的是功能更强大的新版浏览器。无论用户使用何种浏览器,用户都可以访问您的应用。
您可以采用渐进式增强功能,也可以先使用所有浏览器都支持的最基本功能,然后再为新版浏览器添加其他功能。功能检测是覆盖过时浏览器或新浏览器用户的另一种策略。通过功能检测,您可以确定用户浏览器支持哪些功能,然后加载适当的代码。您的应用应使用用户浏览器能够支持的最新功能。
同时针对新式浏览器和旧版浏览器时,您需要考虑一些利弊。首先,您可能需要针对不同的浏览器使用不同的代码。这可能会使代码更复杂且难以维护。您可能无法在所有浏览器中使用最新功能。这可能会限制应用的功能。
根据应用的不同,旧版浏览器可能出于法律原因或业务用例仍需要支持。如果大多数用户都使用的是较旧的硬件,并且无法更新,则可能需要使用 polyfill。polyfill 可为旧版网络浏览器提供现代功能,让您可以使用最先进的 Web 技术和 API,同时仍确保与旧版浏览器兼容。
您可以借助许多功能强大的工具来检查所用的技术或 API:
- Project Baseline:提供在受支持的浏览器中正常运行的功能,并由 Google 和其他常用系统提供支持,致力于改善开发者的体验。
- Caniuse:一项资源,用于查找 Web API 并查看所跟踪的所有浏览器的支持状态。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003eWeb applications should be accessible to all users regardless of their browser choice, potentially using progressive enhancement or feature detection to cater to different browser capabilities.\u003c/p\u003e\n"],["\u003cp\u003eWhile supporting older browsers might necessitate using different code or limit access to the latest features, it can be crucial for legal compliance or business needs, especially when users rely on older hardware.\u003c/p\u003e\n"],["\u003cp\u003ePolyfills can bridge the gap between modern web technologies and older browsers, ensuring compatibility while enabling the use of the latest features.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can utilize tools like Project Baseline and Caniuse to determine browser compatibility and make informed decisions about web development strategies.\u003c/p\u003e\n"]]],["When creating web applications, consider browser compatibility. Employ progressive enhancement by starting with basic features and adding advanced ones for newer browsers. Use feature detection to load appropriate code based on browser capabilities. Supporting both old and new browsers may increase code complexity and limit functionality. Polyfills can bridge the gap by adding modern capabilities to older browsers. Tools like Project Baseline and Caniuse help determine browser support for various technologies.\n"],null,["# Browser compatibility\n\nWhen building a content driven web application, it is important to consider\nwhich browsers your audience is using. Some might use older browsers that don't\nsupport the latest features, while others may be using newer browsers that have\nmore features. Your application is accessible to all users, regardless of their\nbrowser choice.\n\nUtilize progressive enhancement, or start with the most basic features that all\nbrowsers support, and then add additional features for newer browsers. Feature\ndetection is another strategy to reach users with dated or new browsers. With\nfeature detection, you can determine which features are supported by the user's\nbrowser, and then you load the appropriate code. Your application should use the\nmost up-to-date features that the user's browser can support.\n\nThere are a few tradeoffs to consider when targeting both old and modern\nbrowsers. First, you may need to use different code for various browsers. This\ncan make your code more complex and difficult to maintain. You might not be\nable\\\u003e to use the latest features in all browsers. This can limit the\nfunctionality of your application.\n\nDepending on the application, older browsers may still need support for legal\nreasons or business use cases. If the majority of the users are on older\nhardware and cannot update, then polyfills may be necessary. A polyfill provides\nmodern capabilities to older web browsers and can allow you to use the most\nmodern web technologies and APIs while still ensuring compatibility with old\nbrowsers.\n\nThere are many great tools to check what technologies or APIs are used:\n\n- [Project Baseline](https://web.dev/baseline/): is an effort to improve the experience of developers by providing what works well in supported browsers and is backed by Google and other commonly used systems.\n- [Caniuse](https://caniuse.com/): is a resource to look up Web APIs and see the support status across all tracked browsers."]]