Mastering JavaScript High Performance - Sample Chapter
Mastering JavaScript High Performance - Sample Chapter
Mastering JavaScript High Performance - Sample Chapter
$ 44.99 US
29.99 UK
P U B L I S H I N G
Chad R. Adams
Mastering JavaScript
High Performance
ee
pl
C o m m u n i t y
E x p e r i e n c e
D i s t i l l e d
Mastering JavaScript
High Performance
Master the art of building, deploying, and optimizing faster web
applications with JavaScript
Sa
m
Chad R. Adams
), or his website (
).
Book Title:
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.
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.
Part of the reason for this was that the tools used in modern browsers today didn't
exist for Internet Explorer or Netscape Navigator. In the early days of debugging,
JavaScript results were debugged using JavaScript alerts, giving feedback to
developers since the modern tools weren't around then. Also, developer tool sets
today are much more advanced than just simple text editors.
In the following screenshot, we show you a website's download speed using Safari's
Web Inspector:
[2]
Chapter 1
Getting faster
JavaScript, by nature, is a pretty easy language to build. One advantage that JavaScript
has is that JavaScript is an interpreted language, which means that the code developed
can still be deployed, and even work, according to a project's specifications.
Non-compiling code is both good and bad. Without the need to compile, a developer
can quickly build a web page on a full web application in a very short amount of
time. Also, it's very approachable for new- or intermediate-level developers in
general, making staffing for web projects a bit easier.
Now, what's bad about not using a compiled language is that JavaScript doesn't
compile and common errors tend to get missed by the developers involved; even
if the code appears to be working, it may not be working efficiently. During the
days where developer tools were most likely to be Notepad on Windows and a
web browser, any errors were apparent to a user only, leaving out any issues
with regard to code performance.
Today, we have various tool sets and build systems on top of our JavaScript skills.
It's important to understand that having deep JavaScript knowledge can help you
write and review better JavaScript code but, in many cases, we as developers are
only human, and we make common mistakes that affect our JavaScript codenot
adding spaces after a function's starting brackets or forgetting a semicolon at the
end of our code statements, for example.
Choosing a proper editor for a given project that includes basic error-checking
before writing a single line of JavaScript can improve the performance and quality
of our codebase dramatically, without learning anything new in terms of the inner
workings of JavaScript.
Mid-range editors
Lightweight editors
Cloud-based editors
[3]
Each type of editor has its own strengths and weaknesses, and we will review
when to use one over the other, starting with the biggest. The intent is to show
when it's appropriate to move from a larger code editor to a smaller editor in
terms of JavaScript development.
[4]
Chapter 1
It handles multiple languages, including HTML, CSS, and JavaScript, while handling
other language such as C#, Visual Basic, Python, and so forth. In terms of JavaScript,
Visual Studio will check deeply within a project's JavaScript code flow and look for
minor errors that many lighter editors won't find.
For JavaScript developers, the Visual Studio Express Edition for Web should be
powerful enough for any JavaScript projects.
[5]
[6]
Chapter 1
Typically, IDEA is known best as a Java-focused IDE, but it includes the same tools
as WebStorm plus many more. Like Visual Studio, it can handle multiple languages,
but that comes at the cost of performance. For example, if we started working in
both environments on a slower system, we might notice more lag on IDEA than
WebStorm when working day-to-day on JavaScript projects.
Again, this is due to the large number of features the IDEs require to be running in
the background to make our code better, which is more marked on IDEA; so, again,
starting off in an IDE is great to build a well-structured code base early on, but as
time progresses and we work repeatedly in a slow editor, we will need something
faster with a good base already set up.
With that in mind, many developers who don't see performance issues with an IDE
tend to stick with the IDE they've chosen; other developers, however, move on to
editors such as the ones in the next section.
[7]
Mid-range editors
Mid-range editors work very well with projects already past the early phases of
development or projects that are very small. An exception to using an IDE early
on is small projects. These are typically content-management system-based sites,
such as WordPress, Joomla, Drupal, and so on, where most of the JavaScript is
written for the developer and tested already.
They are also useful for light code hinting, and some can connect to either a source
repository or an FTP to push code up. The real differences between these and an
IDE are the speed of the editor and the lack of code quality features. Many of these
editors only look for glaringly obvious errors in the code, such as missing a semi
colon in JavaScript. Nevertheless, they are very useful all-round editors.
[8]
Chapter 1
It also has some support for Python and PHP, but it's not dedicated to running nonweb code on its own. It also features a manual validation checker of JavaScript rather
than one that's continuous so, again, there's some support to improve your JavaScript
and web code, but it does not always check for errors fully while you code.
[9]
For example, if you needed Mac support with Python, then Coda is a good fit, while
WebMatrix gives a different set of features, including ASP.NET support. This is a
common theme in mid-range editors, where many of them are really designed to
do certain things and give just about the minimum support for a code base while
keeping the editor as speedy as possible.
With any editors of this type, we can see that they allow us to connect to an existing
project easily and perform some code-checking while working on a fairly fast editor.
Lightweight editors
There are times where we as JavaScript developers just don't care about the backend
platform a project is using and only need a simple text editor to write a bit of
JavaScript code or update an HTML file. This is where lightweight editors come in.
[ 10 ]
Chapter 1
It is well known for its start-up and usage speeds as well as some basic editing
features, such as language color hinting and basic code-hinting with multiple
language support.
It also has its own package manager called Package Control, which allows you
to augment Sublime Text to automate some common code-editing and compiling
processes. Freshly downloaded, though, it's extremely lightweight and allows
developers to add in common plugins required for their development workflow.
In the case of either of these editors, or any other lightweight editor, as they typically
don't have code validation included, they make code updates easily and quickly with
validation running in the background, at the risk of writing slow or broken code.
Cloud-based editors
Lastly, cloud- or web-based editors are the shiny new tools new to the web developer's
tool belt. They allow a developer to work on a code base inside a browser either as a
plugin to a web browser or purely online, and it allows a developer to work on any OS
platform, Chrome OS, iPad, or Android operating systems that you might not consider
writing JavaScript in!
The advantage of writing code in a browser is that the project code is hosted online,
either in Git or simply in the editor's hosted service. Some plugin editors allow you
to work from your computer's hard drive like any other editor but are written in
HTML and JavaScript with a backend (such as Python, PHP, or ASP.NET) like any
other website.
Typically, these editors fit inside the mid-range editor space in terms of features.
However, some of them can offer very little in terms of features beyond being online
without installing an editor to a computer, which is why they fall in this category.
The upcoming sections give a few examples of popular cloud editors.
[ 12 ]
Chapter 1
It also allows you to clone from a Git URL or from a GitHub project, so you can
choose to have your code hosted in Cloud9 or synced to your own Git repository.
Another feature of Cloud9 is virtual-machine support from the browser for iOS
simulator testing as well as console support for Node.js again, in a browser.
[ 13 ]
This editor is pretty similar to Cloud9, but it hosts cloud service projects, such as
Google's App Engine. It can also build apps for Android while having full JavaScript
support for popular libraries in AngularJS or jQuery.
An issue with cloud editors is that, when JavaScript libraries are involved in a
project, an online editor may not be able to recognize library-specific JavaScript
or HTML tag conventions used, so it's important to consider features when
selecting a cloud editor.
For cloud editors, you can see that they follow a mid-range editor feature-set but
allow for quick connection and updates for existing projects.
[ 14 ]
Chapter 1
Summary
In this chapter, we looked at the history of JavaScript's performance and learned
how it became a focus for developers and businesses. We also reviewed the four
types of JavaScript code editors, and we now understand how to move away from
large IDEs for brand new projects, working down to lightweight editors for small
updates and changes.
In the next chapter, we will look at how we can keep our code's performance quality
high when using a lightweight editor.
[ 15 ]
www.PacktPub.com
Stay Connected: