Performance Optimization
So you've built an application using Dojo and it "feels slow". Now what? Unfortunately, you can't send the latest Dual Core processors to your users But fortunately, experience has taught us that in JavaScript, smaller = faster, no matter what the client. So basically, you want to concentrate on the size of your pages. The smaller they are, the less time it takes to download, parse and execute them.
By default, all dojo.require() statements try to find the module in memory first. If it's not present, it will ask the server for a "full sized" version of the code in a synchronous manner , and incurring network I/O overhead. Synchronous network requests from a browser are necessary for loading external code because it's the only way to block execution of JavaScript while dependencies are satisfied. Once the code is fecthed it is then eval()'d and execution picks up after the dojo.require() statement.
Unfortunately synchronous IO requests also have the effect of "locking" the UI of the browser, preventing loading other resources affecting the layout of the page. Each request is serial. The package system doesn't know enough to try to request multiple files at once. To be fair, scripts included in a page via the <script> tag also suffer from the same serial behavior.
But there are still plenty of things you can do:
-
Use Dojo's custom build system. A custom build of Dojo will improve the download of the page by grouping related modules into one script, and optimizing it for fast parsing. See The Package System and Custom Builds for more information.
- Configure the web server to cache JavaScript files aggressively and send status information quickly. Servers that don't send adequate cache information may find that UIs are very slow even when the script content isn't sent. Instead, browsers may be checking to see if the file has changed since it was last seen. This "has it changed?" check is synchronous and serial and so we want to eliminate it if possible.
- Use data compression and application program structure as your server permits. See the article Improving performance of Dojo-based web applications which contains useful information on these topics.
- If you find IE is repeatedly downloading the same image, read this article for advice. This also helps get rid of ugly image flickering in IE.
- Reduce then number of tags on a page.
It sounds obvious, but many web pages have a lot of unnecessary markup. For example, instead of
just do:<div class="foo">Hello World</div>To achieve this, you definitely want to leverage CSS. The web standards movement has championed this approach, and Dijit uses it for reducing the widget download time. - Instead of downloading your whole page at once, defer portions until the user needs them. The judicious use of ContentPanes nested inside containers
- Printer-friendly version
- Login or register to post comments
- Subscribe post