Chapter 7. Web workers and drag and drop
This chapter covers
- Implementing drag and drop in a desktop browser
- Marshaling data while dragging user interface elements
- Building a multithreaded web application
- Transferring high-cost CPU operations to background threads
This chapter is all about making difficult things simple. In any HTML application with a significant amount of user interaction, you’ll encounter requirements that conflict with one another, such as the need to upload a file or edit an image while maintaining a responsive interface. In this chapter, we’ll show you how to balance the need for a responsive user interface (UI) with the requirement to perform complex, processor-intensive tasks with two new HTML5 APIs: Web Workers and Drag and Drop.
Depending on the host system’s memory and processor, doing any heavy processing can often cause the screen to hang for a few moments. You may even encounter a browser message stating that it thinks you have a runaway process. The Web Worker API provides a good solution to this problem, allowing you to create background workers that can do work in different threads, thus freeing up the UI thread to redraw the page or perform other interactive logic.