After working on a highly available and heavily customized - MOSS Publishing Portal farm, here are few lessons learned on improving SharePoint performance.
General web page improvements: These are applied to branding files and application resources to improve the page loading speed and user experience. Most of them are applicable to any web application. SharePoint handles some of these features natively using blob cache, core files, etc but for custom developed solutions, these items should to be handled manually:
To be continued with Caching, Webpart & other development guidelines.
General web page improvements: These are applied to branding files and application resources to improve the page loading speed and user experience. Most of them are applicable to any web application. SharePoint handles some of these features natively using blob cache, core files, etc but for custom developed solutions, these items should to be handled manually:
- CSS Sprites - are built by grouping small images into one large image and referring part of the image using CSS class. This reduces number of images downloaded from the client browser and improves the overall page loading speed. More details on CSS sprites can be found at http://css-tricks.com/css-sprites/. Since, CSS sprites are not supported in IE6, it cannot be used in organizations that still support IE6.
- Consolidate JS and CSS files - Since number of HTTP requests are more expensive than downloading single large file, consolidating multiple JS or CSS files into single large file would improve the overall resource load times. Also, we observed that combining most commonly used files together yielded better performance (combining too many files may adversely impact the download speed & processing performance due to large file size).
- Group CSS files by Browser type - Since, browser type is unique for each customer request, we observed it as the best way to combine the commonly used CSS files. Also, CSS expressions were avoided due to performance concerns.
- Anonymous access for CSS, JS and image files - Since NTLM requests require at least one additional roundtrip (typically for 401 unauthorized responses), enabling anonymous access to unsecure branding resources reduces the number of roundtrips and improves the page download speeds.Also, when SharePoint return “401 unauthorized” response, it includes the entire Error page response (see in Fiddler), reducing the size of “401 unauthorized” page would reduce the response payload and reduce bandwidth utilization.
- Cache JS, CSS and image files in browser - Since SharePoint supports this natively, no additional work is required to cache the resource files. However, if the resource files are dynamic in nature (changes with releases) then these resources should be accessed using unique querystring to invalidate the browser cache.In our implementation, to ensure unique query string for JS & CSS files, a simple HTTP handler was implemented to render unique query string based on file checksum. Files hosted in SharePoint layouts folder can use MakeBrowserCacheSafeLayoutsUrl() function to render unique url.
- Avoid Minification of JS and CSS - Minification removes extra characters and spaces in the JS & CSS files to reduce the file size and to improve the download speed. However, when the file is compressed, the minified file has little or no change in the download. Also, a minified file is harder to troubleshoot than a regular file. So, Minification was avoided for better maintainability.
- Include JS files and CSS files in the header - Since browser interpret HTML head content and body content differently, i.e., all script references in head tag are loaded after the page is loaded and references in body tag are loaded at the time page load, reducing the referenced content in body improves the page rendering experience.
This is achieved - by referencing all required scripts at the time of page load in body tag and rest of them in the head tag. CSS files are always referenced in head tag.
- Content delivery network (CDN) - has unique advantages such as geographical distribution of data and parallel loading of resources in the web page. This can be utilized to improve the SharePoint performance. Also,
- Since CDNs have higher percentage of availability and throughput, moving the branding elements to CDN can benefit the performance.
- When CDN files are accessed over multiple domain names, it enables Browser to download the files in parallel (applicable to IE6 or older browsers).
- JS and CSS files compression - Natively supported for files hosted in SharePoint. For files hosted outside SharePoint, compression greatly improves the download speeds.
- Use JQuery library or an equivalent library - There are number of reasons to use JQuery but based on our observation the performance benefits were clearly visible as the code grew larger. Also, improved overall quality of code.
To be continued with Caching, Webpart & other development guidelines.

6 comments:
>> Include JS files and CSS files in the header
I don't think that this is right. You can check that easily by creating a test.html. Scripts in head are loaded before dom is created or rendered. They block the rendering of the site.
The above comment is correct. And the purpose of the "Defer" property of the ScriptLink control.
"Avoid Minification of JS and CSS"
I don't think that's right either:
SharePoint 2010 minifies JS files which saves ~100kb for CORE.js alone.
A web server hosting SharePoint with GZIP compression enabled saves an additional ~157kb on CORE.js.
This results in 80kb on-the-wire for core.js when the original, non-minified size is 364kb
The core.debug.js solves the debugging 'problem', using the .debug version when debug=true in the web.config.
"Since, CSS sprites are not supported in IE6, it cannot be used in organizations that still support IE6."
Not quite true either. CSS Sprites are available in any browser that supports javascript -or- a background-position property (depending on the sprite implementation), which both IE5 and IE6 do support.
http://stackoverflow.com/questions/1227412/css-sprites-and-ie6
"CSS expressions were avoided due to performance concerns." Good, since they're no longer supported in IE8 or later in IE8 mode.
"Consolidate JS and CSS files" Good policy. In SP2010, the CssLink/ScriptLink controls are highly useful and append unique query strings to the Css/JS files without additional code.
Thanks for the comments.
"Include JS files and CSS files in the header". Thanks for the correction. The grouping process still applies but the reason for late execution is "defer" tag and not the location of the script.
"Avoid Minification of JS and CSS" - based on my testing, when the javascript files were compressed and compressed w/ Minification, the size difference was less than 5% for all files. But it introduced a level of complexity to diagnose production/environment issues. So, you have to test it for your files and make that call. In our case, "Minification was avoided for better maintainability.".
I see, CSS sprites are supported in IE6. I have to test it out.
Well nice piece of information guys :) can you please also tell me about StorageEdge? It is really worth using? Will I get benefits like "scalability" once I start using it? If you see their page http://www.alachisoft.com/storageedge/index.html they are promising many things like SharePoint Scalability, SharePoint Performance etc but I am not sure if it really works?
Any help in this regard will be highly appreciated.
Best,
Elvira
@Elvira; Yes, we've been using StorageEdge for BLOB offloading and it really has been great experience. We've almost offloaded 2 TB of content from our database to file system. And the best thing that stands them out is caching.
@Elvira; Yes, we've been using StorageEdge for blob offloading and it has worked great. The best they've got is caching of blobs.
Post a Comment