Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

JavaScript Best Practices

There are a number of considerations that you should take into account when writing JavaScript code. Whether you’re trying to tune your code for better performance or test it for compatibility, these best practices can help your code perform better and be more compatible.

If you’re looking for performance and testing tips for JavaScript coding, read this chapter.

Contents:

Memory and Performance Considerations
Testing Your Code
Global Scope Considerations
JavaScript Toolkits


Memory and Performance Considerations

This section includes a number of tips for minimizing your JavaScript application’s memory footprint and helping it perform better.

Testing Your Code

When creating a JavaScript application, consider these tips for testing your code.

Global Scope Considerations

When writing JavaScript code, it’s good practice to avoid placing code and variables within the global scope of the file. Here are some considerations to consider regarding global scope:

JavaScript Toolkits

JavaScript toolkits enhance productivity but often carry a significant memory footprint that may slow down your JavaScript application. When using a toolkit, try to reduce the toolkit’s footprint to just the APIs that you use in your application.

Also, if you’re developing a Dashboard widget, try to avoid bundling the Apple-provided Apple Classes within your widget; instead, follow the instructions provided in Introduction to the Apple Classes.



< Previous PageNext Page > Hide TOC


Last updated: 2008-11-19




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice