Archive for the ‘performance’ Category

JavaScript Optimization for Page Load Performance

Monday, August 27th, 2007

Using techniques like validation, obfuscation, and compression can result in significant decreases in file size, sometimes 50 to 75 percent. Combine that with several other non-pragmatic methods, dramatic improvements in page load performance can be realized.

Care for JavaScript

Building and developing frameworks along with following web standards and some form of a design pattern will help combat against careless coding. Another artifact of building a framework will be more rapid development times and more cohesive packages. At the time of this writing the de facto example of a JavaScript framework is prototype which is protected under open source licenses; MIT and CC-SA (Creative Commons – Share Alike). Caring for the JavaScript also means caring for the HTML it will be run in. Avoid JavaScript only methods that cause the browser to render abnormally, have your code degrade gracefully, if a browser is not JavaScript enabled.

Be Patient with JavaScript

Sometimes it is not necessary to load all the JavaScript in the head of the document or the body onload event. Do not make it standard practice to place all code at the beginning; rather look closely at what code could be placed at the end of the document, at the beginning, or when the page has completely loaded. Delay loading of JavaScript whenever possible, being patient with it will make your browser very happy. And remember to load only what you need. Why load code that is not necessary for the page?

Put JavaScript on a Diet

Once the code is written and the unexpected features have been fixed, you are ready to place your JavaScript on a diet. Remove excess whitespace and comments, use semicolons to break lines in code, and abbreviate variable and object names. This process can be done manually or automatically with vendor packages. Two resources for automatically reducing the JavaScript file size are JavaScript Crunchinator and ESC. Remember to always backup your files before placing it on a diet. To potentially further reduce file size and keep prying eyes from easily reading the source, using an obfuscation tool is recommended. Here is an example of one such tool, you can find many more on the interweb.

Have JavaScript Files Carpool

Roughly 80% of the users’ response time is spent of the client-side. The greater number of JavaScript resources needed in turn produces a greater number of HTTP requests needed. A way to reduce the number of requests is to combine the JavaScript files to a single script. The fewer number of HTTP requests used, the better response time the user will observe.

Optimizing PHP & SQL

Tuesday, May 17th, 2005

Commonly we see php being used as an interface between the client and the database providing the information. Very few implementations utilize optimization, and thus, reduce performance. Listed below are many techniques that should be used to optimize php to sql communication.

  1. Do not use SELECT * unless you must
  2. Use SELECT priorities for better control
  3. SELECT var IN ([constance,...]) is very fast
  4. Use default values for INSERT when you can
  5. Do not create indexes you are not going to use
  6. Indexes are good for reads, but bad for writes
  7. When joining tables, use numbers instead of strings if you can
  8. Create your tables with a fixed-table format if possible
  9. Use OPTIMIZE TABLE and ANALYZE TABLE regularly

There are other techniques both in php design and database design that will optimize performance, but in terms of php and sql communication, this list will get you running more efficiently.