Book Image

Mastering JavaScript High Performance

By : Chad R. Adams
Book Image

Mastering JavaScript High Performance

By: Chad R. Adams

Overview of this book

<p>Studying JavaScript performance in depth will make you capable of tackling the complex and important tasks required to solve performance issues. In this book, you'll learn when and why to use an IDE over a common text editor. Packed with examples, you'll also learn how to create a build system to test and deploy your JavaScript project by optimizing the code. Next, you will move on to learn about DOM optimization, JavaScript promises, and web workers to better break up your large codebase. You will also learn about JavaScript performance on mobile platforms such as iOS and Android and how to deploy your JavaScript project to a device. Finally, by the end of the book, you'll be able to pinpoint JavaScript performance problems using appropriate tools, provide optimization techniques, and provide tools to develop fast applications with JavaScript.</p>
Table of Contents (17 chapters)
Mastering JavaScript High Performance
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
The Need for Speed
5
Operators, Loops, and Timers
Index

Preface

Welcome to Mastering JavaScript High Performance. In this book, we have covered JavaScript performance in a way that helps any JavaScript developer, whether they are new to the language or are experienced veterans. This book covers common performance bottlenecks, how to look for performance issues within code, and how to correct them easily.

We also review modern ways of optimizing our JavaScript code not just by relying on sheer knowledge of JavaScript, but by using tools to help optimize code for us. These tools include Gulp and Node.js, which help create great performing builds, and Jasmine, a JavaScript unit-testing framework that helps discover application flow issues in JavaScript. We also debug a hybrid app using Apple Xcode debugging tools for HTML and JavaScript.

What this book covers

Chapter 1, The Need for Speed, explains the need for faster JavaScript, discusses why JavaScript code is traditionally slow, and shows the types of code editors that can help us write faster JavaScript, without changing our coding style.

Chapter 2, Increasing Code Performance with JSLint, explores performance fixes in JavaScript, and covers JSLint, a very good JavaScript validation and optimization tool.

Chapter 3, Understanding JavaScript Build Systems, teaches you JavaScript build systems and their advantages for JavaScript performance testing and deployment.

Chapter 4, Detecting Performance, covers Google's Development Tools options and contains a review of how to use a Web Inspector to improve our JavaScript's code performance.

Chapter 5, Operators, Loops, and Timers, explains operators, loops, and timers in the JavaScript language and shows their effect on performance.

Chapter 6, Constructors, Prototypes, and Arrays, covers constructors, prototypes, and arrays in the JavaScript language and shows their effect on performance.

Chapter 7, Hands off the DOM, contains a review of the DOM in relation to writing high-performance JavaScript, and shows how to optimize our JavaScript to render our web applications visibly faster. We also take a look at JavaScript animation and test performance against modern CSS3 animation.

Chapter 8, Web Workers and Promises, demonstrates web workers and promises. This chapter also shows you how to use them, including their limitations.

Chapter 9, Optimizing JavaScript for iOS Hybrid Apps, covers optimizing JavaScript for mobile iOS web apps, (also known as hybrid apps). Also, we take a look at the Apple Web Inspector and see how to use it for iOS development.

Chapter 10, Application Performance Testing, introduces Jasmine, a JavaScript testing framework that allows us to unit-test our JavaScript code.

What you need for this book

For this book, you will need a basic understanding of JavaScript, how to write functions and variables in JavaScript, how to use basic web technologies such as HTML and CSS, as well as some basic debugging skills using a Web Inspector such as Chrome Developer tools or Firebug, to name a few.

You will need a text editor, preferably for HTML and JavaScript coding; the available choices are covered in Chapter 1, The Need for Speed. Choosing the editor and the admin rights to the system you're working on is up to you, and it also depends on your budget. Also, Chapter 9, Optimizing JavaScript for iOS Hybrid Apps, strictly covers JavaScript in iOS development; for that, you will need a copy of Xcode and an Intel-based Mac. If you don't have these, you can still read along but, ideally, most of this work is done with a Mac.

Who this book is for

This book is written for intermediate JavaScript developers. If you are experienced with unit-testing JavaScript and writing your own frameworks, and are able to understand what instance-based versus static-based is in JavaScript, this book may not be for you. Also, if you're very new to JavaScript—as in, "How do I use a function?"—I recommend looking for a beginner's JavaScript book as well.

However, if you've been into JavaScript for a while but are new to node-style performance testing, grunt or gulp project deployments, and unit-testing in JavaScript, or if you want to know more on how to write JavaScript faster, or if you're just looking to stop your code base from lagging behind without reworking your coding style, you are reading the right book.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and explanations of their meanings.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "To solve this issue, modern browsers have implemented new console functions called console.time and console.timeEnd."

A block of code is set as follows:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Jasmine Spec Runner v2.1.3</title>

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Clicking on the Next button moves you to the next screen."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from: https://www.packtpub.com/sites/default/files/downloads/7296OS_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.