Dom scripting

Page 294

CHAPTER 12 ■ PUTTING IT ALL TOGETHER

if (submitFormWithAjax(this, article)) return false; return true; } } } Now submit your form, and you’ll see your thank-you message appear without the entire page reloading. You can check this by looking at the browser’s address bar. After the form submits, notice you’re still on the contact.html page, not the submit.html page, as you were before. The contact page is finished, and with it, the website.

Minification Your website is now working as expected, but there's one last thing you can do to improve its overall performance. At the moment, the global.js file is about 13KB. That is not too big, but you can make it smaller by minifying it. As discussed in Chapter 5, several different minification tools are available. Here, let’s use Google’s Closure Compiler. It has a nice web form that will let you paste your JavaScript into it and get back a minified result. Open http://closure-compiler.appspot.com/home in a web browser and copy and paste your global.js into the text area under the // ADD YOUR CODE HERE line, as shown here.

Click the Compile button, and you’ll be presented with a compiled version of your code, along with before and after statistics. For my working global.js file, I got these results:

276


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.