• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Minimize HTTP Requests

Like CSS, your JavaScripts should be designed to maximize speed by minimizing the number of HTTP requests they require. You can embed smaller JavaScripts within high-traffic pages to avoid an extra HTTP request (with caveats for XHTML, discussed in Chapter 5, “Extreme XHTML”), and for site-wide bandwidth savings, use external files. Group files where possible to minimize the overhead of additional file requests.

Upon first encounter, external scripts take one HTTP request per file. I've found CSS files are cached more reliably than JavaScript files, however. External JavaScripts can continue to spawn HTTP requests even after their first encounter.[5] Unlike HTML objects (like images, Flash, and Java), which can be requested in parallel, the HTML parser must wait for the JavaScript interpreter to load and execute any JavaScript files before it can continue.

[5] Netscape Communications, “Problems caching .js source files?,” in DevEdge Newsgroup FAQ [online], (Mountain View, CA: Netscape Communications, 1999), available from the Internet at http://developer.netscape.com/support/faqs/champions/javascript.html#2-9. Add the following line to the mime types file to force Netscape to cache .js files properly: application/x-javascript exts=js.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint