Table of Contents for
The Modern Web

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition The Modern Web by Peter Gasston Published by No Starch Press, 2013
  1. The Modern Web
  2. Cover
  3. The Modern Web
  4. Advance Praise for
  5. Praise for Peter Gasston’s
  6. Dedication
  7. About the Author
  8. About the Technical Reviewer
  9. Acknowledgments
  10. Introduction
  11. The Device Landscape
  12. The Multi-screen World
  13. Context: What We Don’t Know
  14. What You’ll Learn
  15. A. Further Reading
  16. 1. The Web Platform
  17. A Quick Note About Terminology
  18. Who You Are and What You Need to Know
  19. Getting Our Terms Straight
  20. The Real HTML5
  21. CSS3 and Beyond
  22. Browser Support
  23. Test and Test and Test Some More
  24. Summary
  25. B. Further Reading
  26. 2. Structure and Semantics
  27. New Elements in HTML5
  28. WAI-ARIA
  29. The Importance of Semantic Markup
  30. Microformats
  31. RDFa
  32. Microdata
  33. Data Attributes
  34. Web Components: The Future of Markup?
  35. Summary
  36. C. Further Reading
  37. 3. Device-Responsive CSS
  38. Media Queries
  39. Media Queries in JavaScript
  40. Adaptive vs. Responsive Web Design
  41. Viewport-Relative Length Units
  42. Responsive Design and Replaced Objects
  43. Summary
  44. D. Further Reading
  45. 4. New Approaches to CSS Layouts
  46. Multi-columns
  47. Flexbox
  48. Grid Layout
  49. The Further Future
  50. Summary
  51. E. Further Reading
  52. 5. Modern JavaScript
  53. New in JavaScript
  54. JavaScript Libraries
  55. Polyfills and Shims
  56. Testing and Debugging
  57. Summary
  58. F. Further Reading
  59. 6. Device Apis
  60. Geolocation
  61. Orientation
  62. Fullscreen
  63. Vibration
  64. Battery Status
  65. Network Information
  66. Camera and Microphone
  67. Web Storage
  68. Drag and Drop
  69. Interacting with Files
  70. Mozilla’s Firefox OS and WebAPIs
  71. PhoneGap and Native Wrappers
  72. Summary
  73. G. Further Reading
  74. 7. Images and Graphics
  75. Comparing Vectors and Bitmaps
  76. Scalable Vector Graphics
  77. The canvas Element
  78. When to Choose SVG or Canvas
  79. Summary
  80. H. Further Reading
  81. 8. New Forms
  82. New Input Types
  83. New Attributes
  84. Datalists
  85. On-Screen Controls and Widgets
  86. Displaying Information to the User
  87. Client-side Form Validation
  88. The Constraint Validation API
  89. Forms and CSS
  90. Summary
  91. I. Further Reading
  92. 9. Multimedia
  93. The Media Elements
  94. Media Fragments
  95. The Media API
  96. Media Events
  97. Advanced Media Interaction
  98. Summary
  99. J. Further Reading
  100. 10. Web Apps
  101. Web Apps
  102. Hybrid Apps
  103. TV Apps
  104. Webinos
  105. Application Cache
  106. Summary
  107. K. Further Reading
  108. 11. The Future
  109. Web Components
  110. The Future of CSS
  111. Summary
  112. L. Further Reading
  113. M. Browser Support as of March 2013
  114. The Browsers in Question
  115. Enabling Experimental Features
  116. Chapter 1: The Web Platform
  117. Chapter 2: Structure and Semantics
  118. Chapter 3: Device-Responsive CSS
  119. Chapter 4: New Approaches to CSS Layouts
  120. Chapter 5: Modern JavaScript
  121. Chapter 6: Device APIs
  122. Chapter 7: Images and Graphics
  123. Chapter 8: New Forms
  124. Chapter 9: Multimedia
  125. Chapter 10: Web Apps
  126. Chapter 11: The Future
  127. N. Further Reading
  128. Introduction
  129. Chapter 1: The Web Platform
  130. Chapter 2: Structure and Semantics
  131. Chapter 3: Device-Responsive CSS
  132. Chapter 4: New Approaches to CSS Layouts
  133. Chapter 5: Modern JavaScript
  134. Chapter 6: Device APIs
  135. Chapter 7: Images and Graphics
  136. Chapter 8: New Forms
  137. Chapter 9: Multimedia
  138. Chapter 10: Web Apps
  139. Chapter 11: The Future
  140. Index
  141. About the Author
  142. Copyright

Web Apps

I’ll begin by looking at web apps, that is, apps built entirely using web platform technologies. Although called web apps, they don’t necessarily have to exist on the open Web; they can also be packaged and distributed through online stores for download onto devices. There are, of course, many online stores, but I’ll look specifically at two with the lowest barriers to entry: the Chrome Web Store, which has been around for a few years, and the newer Firefox Marketplace. While both are created by browser vendors, the big difference between them is that the Chrome Web Store works only in the Chrome browser, whereas the Firefox Marketplace is aimed at creating an open standard that any browser can use.

Hosted vs. Packaged Apps

Before moving on to look at the different app store requirements, let’s take a few minutes to define two subdivisions of web apps: hosted and packaged. Although most web app stores accept submissions of either, each type of app has certain advantages or disadvantages (largely around restrictions or permissions to core device functions), which are useful to know about in advance to help you choose the right approach to building your app.

Hosted Web Apps

A hosted app is one that holds all files on an external web server, usually accessible via a public URL. Essentially, a hosted app is like a website with a little extra metadata to allow app stores to index it. A hosted app isn’t installed onto a device; a shortcut is created on the device that launches a browser or embedded web view when the user decides to open the app.

Hosting a web app has the advantage of allowing you, the developer, to make updates without requiring reauthorization from a store, but the flip side is that the security risk is higher (an evil developer could smuggle in compromising code), so hosted apps generally don’t get access to restricted device APIs.

Packaged Web Apps

Unlike hosted apps, a packaged app contains all the assets necessary to run it, compressed (usually zipped) in a single file. All the files are installed on the device, and although the app can connect to external web services, such a connection isn’t always required. Packaging an app in this way means the store owner can review and authorize the app’s contents and grant extra permissions if the app is found to be secure; in practice, this means the developer can access restricted APIs on the device, such as those used to access the address book or text messaging functions.

Packaged apps open and shut more quickly than hosted ones because all their files are held on the user’s device, so they’re less dependent on network capabilities. But packaged app developers need to be sure to store data locally and allow it to be synced to the data server while online, which requires more development work. To help with this, you can use local storage (discussed in Chapter 6), but for more extensive offline access options, you’ll want to use AppCache, which I cover in Application Cache.

Manifest Files

Regardless of whether an app is hosted or packaged, every app designed for an app marketplace has to contain some data that’s formatted or presented in a specific way in order to identify it as an app that belongs in that particular store. Usually this process involves no more than filling in a few required data fields and adding an icon to display on the target device, both of which are contained in a manifest file.

The manifest file is a simple XML or JSON text file hosted somewhere in the folder that holds your site assets. It contains key information about the app, including its name and description, although the required information varies slightly between stores, as I explain in the following sections.

The Chrome Web Store

When hosted by the Chrome Web Store, the manifest file must be JSON-formatted, named manifest.json, and stored in a folder called myapp in the app’s root folder. The following annotated code shows a short example of manifest.json for the Chrome Web Store, with the bare minimum of required fields.

  {
1   "name": "App Name",
2   "description": "Short description",
3   "version": "0.1",
4   "manifest_version": 2,
5   "icons": {
      "128": "icon_128.png"
     },
6   "app": {
      "launch": {
       "web_url": "http://foo.example.com/"
     }
   }
  }

The first item 1 in the manifest is the name of your app. Next 2 is the description, which should be 132 characters (or fewer) in length and contain no HTML. The version property 3 is the custom release version of your app, which is handy for bug reporting and informing users of updates. The manifest version 4 tells the Chrome Web Store that you’re using the most up-to-date manifest format (version 1 will be phased out throughout 2013).

The icons object 5 is a list of image files that are to be displayed at different resolutions, depending on where they will be shown (such as on a device desktop or in a list of apps); here, the file icon_128.png will be used whenever a 128×128px icon is displayed. Finally, the app object 6 contains a web_url subfield, which includes the URL of the page to be displayed when your app launches.

The Firefox Marketplace

The manifest required by the Firefox Marketplace is known as an Open Web App Manifest. As the name implies, Mozilla is hoping this format becomes a general standard for web apps, as a way to simplify the process of submitting a web app to multiple stores in the future. This manifest is usually called manifest.webapp and served with the MIME type application/x-web-app-manifest+json. Full instructions can be found in the slides of Robert Nyman’s talk “WebAPIs and Apps” listed in Appendix K.

The Open Web App Manifest file is JSON-formatted and, by design, similar to that of the Chrome Web Store. The listing here shows a minimal, annotated example.

  {
1   "name": "App Name",
2   "description": "Short description",
3   "version": "0.1",
4   "launch_path": "http://foo.example.com/",
5   "icons": {
      "128": "icon_128.png"
    }
  }

The name 1 and version 3 fields and the icons object 5 are the same as previously described for the Chrome Web Store. The description field 2 is the same too, except that its length can be up to 1024 characters. The biggest difference is the launch_path 4 field, which has the same behavior as app > launch > web_url in the Chrome manifest. No manifest version is required, although one could be added as an extension when submitting the app to the Chrome Web Store (which requires it).

W3C Widgets

The W3C has developed their own standard for packaged web apps, known in their parlance as widgets. Widgets work like other packaged web app formats, except that the manifest file (called config.xml) is in XML format, and all the files are zipped with the suffix .wgt.

As it’s in XML, the manifest file is a little different from the ones I’ve already shown you, although most of the information in it should be familiar:

<widget version="0.1">
  <name>App Name</widgetname>
  <description>Short description</description>
  <content src="http://foo.example.com"/>
  <icon src="icon_128.png"/>
</widget>

Having been around for a while, widgets are considered quite stable, but they don’t have many implementations in the modern device environment. The Opera browser uses a widget as a base for its extensions specification, but the largest current user of the widget is probably the PhoneGap project, which I cover next.