Modern Web Apps should be focused, rich, and gorgeous, but they also need to be FAST. After all, being rich and beautiful isn't always enough!
With web apps, faster is always better; nobody will ever complain that your site is too fast!
139. Set up Web Worker communication on the web page and in the worker (similar to Cross Document Messaging):
140. Set up event listener to listento incoming messages and errors from the worker
141.
142. Web Workers API JavaScript //From the main page worker.postMessage("Here's a message for you"); //Add event listener worker.addEventListener("message”, messageHandler, true); //Process incoming messages function messageHandler(e) { // process message from worker } //Handle errors worker.addEventListener("error", errorHandler, true); //Stop worker worker.terminate();
143. Web Workers API JavaScript //From the Web Worker function messageHandler(e) { postMessage("worker says: " + e.data + " too"); } //Add event listener addEventListener("message", messageHandler, true); //Using a Web Worker within a Web Worker var subWorker = new Worker("subWorker.js");
144.
145. You can create “inline Web Workers” on-the-fly using the (new) File API:
164. Add as attribute to the HTML elementHTML <!DOCTYPE html> <html manifest="offline.appcache"> <head> <title>HTML5 Application Cache Rocks!</title> Example appcache Attribute