拥抱渐进式 Web

Ten years ago, when smartphones were the new thing, the message went out that you needed to have a stand-alone app to run on the phone. Mobile development was a new kind of programming with unique challenges, but there were good reasons to do it at the time, such as top performance and promotion and software updates managed through the app store. However, to get access to all the features of the mobile device, you needed to write native code.

Today, mobile development still has unique challenges and expenses. However, the good reasons to invest in it have been frittering away. An alternative model, the progressive web, looks like a better choice when you consider all the factors.

To the user, a progressive web app (PWA) looks and behaves like a native app. It doesn’t look like the software is running in a web browser; it works when the device is offline; and users launch it from an app icon just like a “real” app. But behind the scenes, the app is not running as a native program on the device but as a full-screen website in the browser.

There are many significant advantages to choosing the progressive web model over the native app model, including:

  • The client-side programming on all platforms is HTML/CSS/JavaScript. All means all, meaning the same web application can work with phones, tablets, desktops, notebooks, servers, watches—anything with a standards-compliant browser. You don't need to develop expertise in Objective-C for iOS, Java for Android, and something else for desktops.
  • Updating the application involves changing files on the servers under your control. Apple and Google don’t need to be involved at all. Changes go out to all users at once (assuming the users are online).
  • The programming model is standards-based, not controlled by one vendor.

That last bullet point is technically accurate, and yet it raises an important issue and the main problem with adopting progressive web apps today: The driving force behind PWAs is Google.

Innovation in your inbox. Sign up for the weekly newsletter.

Subscribe now

Implementation issues

Google is, by far, the most aggressive in adopting new browser standards behind PWAs in Chrome. Other vendors, such as Mozilla, Microsoft, and, in particular, Apple, have been much less aggressive, though the April 2018 Microsoft update brings with it EdgeHTML 17, the fifth major version of the Microsoft Edge rendering engine. This release claims new developer capabilities for websites and web apps, including the foundation for full-featured PWAs on Windows.

This presents a major practical problem, since all web browsers on Apple’s iOS operating system, including Google Chrome, have to use Apple-provided rendering and JavaScript engines (see Section 2.5.6: “Apps that browse the web must use the appropriate WebKit framework and WebKit JavaScript.”) So PWA features can work on iPhones and iPads only if Apple supports them, and many of these features are unsupported in WebKit.

These new standards go beyond what most think of as HTML and JavaScript features. They create standards for a web audio API to process and synthesize audio, a JavaScript event for handling individual keyboard presses and releases, a speech synthesis API, and an API for getting input from USB gamepads. There is very little you can do in a native app that you can’t do in a PWA.

Apple, it should be noted, has a clear business interest in keeping apps native: Such apps must be distributed through its app store, where the company takes a large percentage of the app sale price, proceeds from in-app purchases, and advertising revenue. With PWAs, there is no need for a store to distribute apps, and since the software is just webpages, the advertising is done through the conventional web advertising networks (which are dominated by Google).

However slowly, Apple is adopting many of the key standards behind PWAs. If there is one most important standard for PWAs, it is service workers. Service workers, which are web code triggered by an event, run in the background of the webpage, basically like threads. Numerous other standards have extended service workers, such as Web Background Synchronization, which allows service workers to work, or to at least stay alive, even when faced with common challenges such as a user shifting away from the browser or the network becoming unavailable.

A certain sense of inevitability

Apple added support for service workers in iOS 11.3 and macOS High Sierra 10.13.4, although so far, only for the Safari web browser and applications that use the Safari control for browsing. Version 17 of Microsoft’s Edge browser, currently in pre-release and scheduled to be released very soon, will support them. At that point, all major browsers will support service workers and their rate of adoption should increase.

The advantages of PWAs are important for enterprises, not just for app startups. The ability to have one code base serving to desktops, phones, and tablets of any brand is a major plus for development savings and software quality. And when you need to make changes, you can do so just by updating the web server. This tracks well with the mobile-first approach that many websites are already taking.

So, if these PWAs are so great, where are they? Most existing PWAs are just demo-level programs. Wikipedia has a list of some. Ginger is a WebGL morphing demo that gets the point across of how far the web has come since, well, Wikipedia. Note that, just as the PWA rules require, Ginger lets you add an app icon for itself to the home screen and runs without any browser, just like a native app.

“Web apps” for devices aren’t strictly new. More than one company, Apple among them, has tried to make the web the programming model for mobile devices. But until Google put a lot of effort into advancing HTML and JavaScript standards, web apps were just too limited in capability. This was a feature, not a bug, of early web browsers to make web software unthreatening.

Google’s major push for PWAs came at the 2016 Google I/O conference. Most of its materials on the subject still relate to that event. The company's PWA checklist is a good guide to what (Google argues) defines such an app. Its baseline requirements are:

  • Site is served over HTTPS.
  • Pages are responsive on tablets and mobile devices. (Google has specific time requirements for this.)
  • All app URLs load while offline.
  • Metadata is provided for add to home screen.
  • First load is fast even on 3G.
  • The site works cross-browser.
  • Page transitions don't feel like they block on the network (really a variant on the responsiveness requirement).
  • Each page has a URL (i.e., single-page apps beware).

That’s just the baseline. Among other things, an “exemplary” PWA:

  • Dims the screen when a permission request is showing.
  • Appropriately informs the user when they're offline.
  • Loads very fast, even on 3G.
  • In general, doesn’t annoy the user with excessive prompts and notifications.

Adherence to these standards and the standards for HTML, CSS, and JavaScript should allow PWAs to work with little or no modification across all compliant web browsers and operating systems. This is, once again, not necessarily what Apple and Google have in mind, but it’s an inevitable outcome of a good standards process.

Historically, the challenge for standards such as these has been the arrival of new hardware features (imagine a camera detail such as zoom levels) that would be available to native code but not in the standard and inconsistently supported on different hardware platforms. Eventually, the hardware features become standard enough that a JavaScript-accessible API standard is warranted. The rate of such changes in the phone and tablet market has declined markedly in the past few years, and so it is increasingly possible to write PWAs that work effectively on all important platforms.

The other major challenge has been performance. HTML, JavaScript, and CSS are all high-level conceptual languages, and browsers can consume a lot of resources. Even on a full PC, browsers can feel slow, and certainly things would be worse on a phone. This problem has been addressed by more optimal programming of the browsers themselves and, more important, better hardware. The A11—Apple’s 64-bit processor in the iPhone 8, iPhone 8 Plus, and iPhone X—has 6-CPU cores; the Samsung Galaxy S8 and newer families offer 8-core CPUs from Qualcomm and Samsung depending on market, offering processing power that would be respectable on a desktop.

Progressive standards

There are also new web standards to improve performance of web apps, perhaps the most important being WebAssembly. This standard is a (machine) assembly language for a virtual machine architecture that can be served as part of a web app from the server. A developer compiles it from C, C++, or some other high-level language. It doesn’t run directly on the phone processor, but the translation from it to native code is simple and straightforward compared with that from JavaScript. The Mozilla description of WebAssembly explains it well. WebAssembly is supported by all the major browsers, including Safari.

If Apple is really resisting PWAs, it’s no longer a full-throated resistance. PWAs are not the talk of the tech town yet, but there is a certain inevitability to them. It makes sense. The day will come when you won’t have to go to the app store to get real, professional software for mobile devices. You might still want to, and Apple and Google will want you to, but it won’t be necessary. PWAs are yet another way technology will bootstrap innovation.

Progressive web apps: Lessons for leaders

  • The advantage of PWAs is simplified development that applies across platforms.
  • They rely on new standards that build on existing standards and technologies.
  • PWAs are a logical extension of existing trends.

来源:JavaScript中文网 ,转载请联系管理员! 本文地址:https://www.javascriptcn.com/post/32493


猜你喜欢

  • GraphQL:用 Connection 优化节点查询

    前言 GraphQL 是一种由 Facebook 开发的数据查询和操作语言,它提供了一种更高效、更灵活的方式来获取和操作数据。GraphQL 的一个重要特性就是可以精确地指定需要查询的数据,避免了传统...

    12 天前
  • Server-sent Events 的浏览器支持情况及解决方法

    什么是 Server-sent Events? Server-sent Events(简称 SSE)是一种基于 HTTP 的服务器推送技术,它可以让服务器向客户端发送事件流,客户端通过监听这个事件流来...

    12 天前
  • ECMAScript 2020(ES11)中的新特性:BigInt 转换

    在 ECMAScript 2020(ES11)中,新增了一种数据类型:BigInt。它是一种可以表示任意大整数的数据类型,可以用来解决 JavaScript 中整数运算的精度问题。

    12 天前
  • CSS Reset 在 IE6、IE7 等老浏览器中的应用

    什么是 CSS Reset CSS Reset 是一种通过重置浏览器默认样式的方式,消除不同浏览器之间的差异,从而实现更加一致的样式效果的技术手段。在前端开发中,使用 CSS Reset 可以让我们更...

    12 天前
  • ES6 中的类继承和原型链之间的关系解析

    在 ES6 中,引入了 class 关键字,使得 JavaScript 也具备了面向对象编程的能力。在类继承和原型链之间,有着密切的关系。本文将详细解析 ES6 中的类继承和原型链之间的关系,并提供一...

    12 天前
  • 如何使用 Redux 处理 React 应用中的表单数据

    前言 在开发 React 应用时,表单数据的处理是非常常见的需求。然而,由于 React 的单向数据流和组件化特性,传统的表单处理方式可能会变得非常繁琐。而 Redux 作为一种状态管理工具,可以帮助...

    12 天前
  • Redis 处理高并发的策略

    前言 随着互联网的发展,高并发已经成为了一个不可避免的问题。而 Redis 作为一款高性能的 NoSQL 数据库,也成为了处理高并发的重要工具之一。本文将会介绍 Redis 处理高并发的策略,并且会提...

    12 天前
  • 响应式设计中的图片适配问题解决方案

    在响应式设计中,图片适配是一个比较棘手的问题。如果不加以处理,可能会导致图片在不同设备上显示不佳,影响用户体验。本文将介绍响应式设计中的图片适配问题,并提供解决方案。

    12 天前
  • 解析 TypeScript 中 encapsulation(封装)的实现方式

    解析 TypeScript 中 encapsulation(封装)的实现方式 在 TypeScript 中,封装(encapsulation)是一种重要的面向对象编程的特性。

    12 天前
  • PM2 崩溃处理:如何避免由于 PM2 进程奔溃导致应用崩溃?

    在前端开发中,我们经常使用 PM2 进行进程管理和部署。但是,当 PM2 进程崩溃时,应用也会跟着崩溃。如何避免这种情况的发生?本文将介绍 PM2 崩溃处理的方法和技巧,帮助您更好地管理和部署应用。

    12 天前
  • 在 Node.js 中运行 HTTPS 服务器的方法

    Node.js 是一个非常流行的 JavaScript 运行时环境,它可以让我们通过 JavaScript 编写服务器端应用程序。在开发 Web 应用程序时,安全性是非常重要的。

    12 天前
  • 详解 ECMAScript 2018 中的三个新操作符及其用法

    ECMAScript 2018 (简称 ES2018) 是 JavaScript 语言的最新标准,其中包含了许多新特性和语法糖。本文将详细介绍其中的三个新操作符及其用法,分别是:扩展运算符、剩余运算符...

    12 天前
  • 解决 Enzyme 测试 React Native 组件时动画无法渲染的问题

    在开发 React Native 应用时,我们经常需要使用 Enzyme 来测试组件。然而,当我们测试涉及到动画的组件时,我们可能会遇到一些问题:动画无法渲染,导致测试失败。

    12 天前
  • 使用 React Router 打造复杂而强大的 SPA 应用

    随着 Web 技术的不断发展,单页应用(Single Page Application,SPA)已经成为了现代 Web 应用的主流。SPA 通过异步加载数据和动态更新页面,提供了更快速、更流畅的用户体...

    12 天前
  • AngularJS 中如何使用 ng-repeat 中的 filter 来过滤数据

    在 AngularJS 中,ng-repeat 指令是用于循环遍历数组或对象并生成 HTML 元素的常用指令。而 ng-repeat 指令中的 filter 属性则是用于过滤数据的功能。

    12 天前
  • 如何在 Chai 中验证 Promise.all

    如何在 Chai 中验证 Promise.all 在前端开发中,Promise.all 是一个非常常用的功能,它可以让我们在多个异步操作完成后再执行一些操作,这个功能在实际开发中非常实用。

    12 天前
  • Mongoose 实现数据批量更新的方式详解

    前言 在前端开发中,经常会涉及到对数据库中的数据进行批量更新的操作。而 Mongoose 是一款 Node.js 平台下的 MongoDB 对象模型工具,它提供了一种方便的方式来操作 MongoDB ...

    12 天前
  • 在使用 lit-element 的时候,如何解决麻烦的 Shadow DOM 的变量传递问题

    前言 在使用 Web Components 的时候,我们通常会使用 Shadow DOM 来实现封装和样式隔离。然而,Shadow DOM 的封闭性也带来了一些挑战,其中之一就是变量传递问题。

    12 天前
  • Tailwind CSS 如何实现动态换肤?

    随着互联网的发展,越来越多的网站和应用开始支持动态换肤功能。动态换肤不仅可以提升用户体验,还可以让用户在不同的环境下选择适合自己的主题,增加用户黏性和满意度。本文将介绍如何使用 Tailwind CS...

    12 天前
  • 如何在 Less 中使用字符串操作函数?

    在前端开发中,样式表是不可或缺的一部分。而 Less 是一种动态样式语言,它是 CSS 的一种扩展。在 Less 中,我们可以使用字符串操作函数来处理字符串,这些函数可以帮助我们更加方便地操作字符串,...

    12 天前

相关推荐

    暂无文章