Making JavaScript faster: From responsive designs to minimizing JSON

With the universal constant in web design being the use of JavaScript, minimal JSON and Cascading Style Sheets, web developers are looking at more ways to develop responsive designs with faster JavaScript code.

JavaScript and JavaServer Pages (JSPs) are the workhorses of enterprise web development in Java, getting all those tedious little tasks done that keep everything else running smoothly. Without them, there’s no dynamo in your dynamic content. Using these technologies properly can mean the difference between a fast running river of highly performant code and a mess of buggy molasses. Here’s some current advice from around the JavaSphere that may help you improve the way you use JavaScript (JS) and JSPs.

If you like your JavaScript to look elegant while getting the job done, you won’t want to miss these tips.

Jason Tee, Enterprise Software Architect

Smart JavaScript techniques and patterns

This timely tutorial at onextrapixel.com is all about functionality in how you actually write your code. If you like your JavaScript to look elegant while getting the job done, you won’t want to miss these tips. For example, do you know when to replace logical operators and comparisons with a simple regex test? This tutorial will help you to find out how. If you aren’t very familiar with the use of regular expressions, you can get started here.

Creating responsive designs

Don’t you hate it how consumer trends keep swinging back and forth from the micro to the macro? First, everyone wants the slimmest or most compactsmartphones. Now, Apple is apparently creating a whopping 12” iPad. The larger the device, the more stuff it can do. That’s fine and dandy for the end user, but trying to create apps that work across such a range of device types and screen resolutions can be a real beast for developers. It becomes necessary to make some tough decisions about what to keep and what to squeeze out when the app is being deployed on a smaller device. Using JavaScript to detect the screen size and then having it update and apply the appropriate CSS styles is one way to implement a smart solution. The Bootstrap library is the most popular pick for this purpose. Foundation isn't bad either. You can see more options here.

Minimizing JSON

What do Java developers do on a winter Sunday? Some of them like to parse JSON. Ralf Sternberg, a committer and project lead for Eclipse RAP, put together a fast and lightweight library with just ten classes. Apparently, going lean with the parser actually improves server performance because "the server processes and creates JSON messages for a large number of clients at a high rate." There are no dependencies on an external JSON library, the code is easy to maintain, and it’s not a memory hog. It isn’t going to be enough for all your JSON projects, but it does a few things well. You can find out more about usage for this mini-library here.

Writing memory efficient code

This article on Smashing Magazine is chock full of goodies for developers coding apps that will run on Google’s V8 or IE’s Chakra, etc. There’s apparently a lot going on behind the scenes with this type of JS engine. It’s important to know what these engines are doing for you. What are they optimizing and what are they unable to do? Is the garbage collector able to pick up the slack and keep things clean?

This educational piece by khoomeister on GitHub Gist has a little something for everyone. Some of the advice is stuff you already know but need to have knocked into your head again (e.g., avoid premature optimization). But you might also learn a few tricks like using iife rather than doSomething so you get one privateHelper rather than recurring nestedHelpers. This is the place to go to brush up fast on the stuff you do every day in JavaScript. Yes, sometimes it stings a little to realize how long you’ve been doing it wrong. But doing it right makes life so much easier! To find more jsPerf benchmark guidelines, click through.

What are your favorite JS and JSP tips and tricks? Let us know your secrets.

Start the conversation

0 comments

Register

I agree to TechTarget’s Terms of Use, Privacy Policy, and the transfer of my information to the United States for processing to provide me with relevant information as described in our Privacy Policy.

Please check the box if you want to proceed.

I agree to my information being processed by TechTarget and its Partners to contact me via phone, email, or other means regarding information relevant to my professional interests. I may unsubscribe at any time.