We can use this form in page like the following, where the user is expected to upload an image. After the form is submitted, the server-side code sends back the page with the image embedded between the div id=”image” tags. The server-side code to handle this is obvious. Furthermore, the form will work with any browser, including a browser without Javascript:

(Please note that in this example, we’ll ignore obvious security measures such as CSRF protection).

Modern browsers, however, have features that can greatly enhance the user experience. We’ll take advantage of them if they’re there. To do so, we’ll start by loading the Javascript libraries that we’ll need: