" /> " /> Learn Dash AJAX Dot Com -
Welcome to Learn Dash Ajax Dot Com

Web Site Performance Tips

Tuesday, December 23, 2008

Making web site pages load quickly is paramount. Here's some tips I recommend from past experiences as well as some stuff that I'm sure has already been mentioned by others on the Net. Some of this is ASP.NET specific but there is still some non general stuff in here too.

  • Minimize the size of image files. Adobe Photoshop and Adobe Fireworks can do this, as well as Gimp plus I'm sure there's tonnes of other graphics editors out there like Google's Picasa. Yahoo! released a tool called Smush It that can do this automatically from a web site, see http://smushit.com/ .

  • Instead of returning DataSets, use DataReaders. When editing something load up the individual record(s). Doing so will eliminate a big chunk of ViewState which will speed up page rendering.

  • Remove all inline CSS, put them as classes and store the classes in CSS files. This improves management of style and allows for you to use the “Cascade” in CSS and the CSS file(s). AS well CSS files are cached by the browser.

  • Remove all JavaScript that is contained in server-side source code, if possible. If ClientIDs of server controls are required, register them through server side code, but pass them as arguments to JavaScript methods stored in *.js files or define them as global variables. Doing so will also allow JavaScript to be cached by the browser.

  • Compress CSS and JavaScript using YuiCompressor, to minify these files. Another alternative is to obfuscate your JavaScript, but I found this to be problematic and difficult to debug. Having said that I successfully used Semantic Designs JavaScript Obfuscator . You have a file which you define your public API so it doesn't get obfuscated. If done right, you can reduce your JS footprint big time.

  • Disable ViewState wherever possible.

  • Cache pages if possible or controls in pages if possible. E.g. For a specific role cache the menu control. You can use ASP.NET’s OutputCache page/control directive.

  • Reduce our markup. Anywhere where tables are used for layout, consider using DIVs or HTML lists and CSS.

  • Set the AutoEventWireUp page directive to false to improve performance. Here's some links explaining why:
  • Use HTTP compression if possible. Here's some links explaining why:
  • Here's also some guidelines from Yahoo, http://developer.yahoo.com/performance/rules.html

  • For ASP.NET, avoid using Server.MapPath as much as possible as it slows down performance. If you need it to resolve a folder, try and load these folders into Application variables when the application starts and then use these base folders to build the folder you need
    protected void Application_Start(object sender, EventArgs e)
    {
    // code ...
    Application[DownloadsFolderApplicationKey] = Server.MapPath("~/downloads/");
    // more code ...
    }

    protected void Session_Start(object sender, EventArgs e)
    {
    // code ...
    if (Application[DownloadsFolderSessionKey] == null)
    throw new NullReferenceException("Downloads folder cannot be null.");

    string downloadPath = Path.Combine(

    Application[DownloadsFolderApplicationKey] as string
    , Session.SessionID);
    // Don't do this
    // string downloadPath = Path.Combine(Server.MapPath("~/downloads/"), Session.SessionID);
    // more code ...
    }

Some other great articles on web site optimization:

Take a peek at FireFox's YSlow Add-On (courtesy of Yahoo!) for optimizing web site performance.

That's all for now. If you have other suggestions for improving page performance, please let me know.

Labels: , , , , ,

IBM's XML Challenge

Tuesday, December 2, 2008
There's a cool post about IBM's The XML Challenge posted by Antonio Cangiano on his blog, Zen and the Art of Programming . The full blog post is here. Sounds like a fun contest if you wanna flex your XML muscle and win some goodies.

Labels: , ,


AddThis Feed Button   Bookmark and Share