Chapter 12. Communicating with other systems and languages

 

This chapter covers

  • Interacting with JavaScript
  • Getting data from external servers with JSONP
  • Running an app without a server
  • Packaging an installable Chrome app

Although you can write an app entirely in Dart, that isn’t the end of the story. Dart apps live in a wider ecosystem encompassing browser apps, existing JavaScript frameworks and libraries, and APIs on third-party servers. Each of these environments has its own challenges in the areas of server availability, browser security, and communication between different virtual machines.

In this chapter, you’ll modify the DartExpense app to interact with external JavaScript by passing messages between the Dart and JavaScript VMs. This modification lets you call out from Dart code to JavaScript code and lets JavaScript code call back into Dart code.

You’ll use this JavaScript mechanism to communicate with third-party servers, such as public Google APIs, by using JSON with padding (JSONP) callbacks. This is a mechanism to return data from a third-party server without the security restrictions around AJAX calls.

Next, you’ll improve DartExpense’s ability to use the offline capabilities provided by HTML5’s AppCache technology, which lets the browser start an app even when the server isn’t available—perfect for mobile apps when you can’t always guarantee connectivity.

12.1. Communicating with JavaScript

12.2. Communicating with external servers

12.3. Building installable, server-less browser apps

12.4. Summary