Professional Documents
Culture Documents
Patterns
For RIA/Web based Applications
By Reddappa Gowd Bandi
Dated on 25th Sep 2007
Introduction:
1. The page loading life cycle will have three different states. Handling
the data and task handling at different stages makes UI is more
reactive towards user.
a. Load state
b. Rendering state
c. Runtime state
2. Eliminate making multiple page level Http requests.
3. Don’t forget to add an Expires header.
4. Use the request/response paradigm through gzip compression
streams. This will depend on case by case. If the data is more than
20KB go for this option.
5. Build JS components are gzip aware.
6. Put the CSS at the top and move scripts to the bottom.
7. Avoid CSS expressions at most.
8. Make Javascript and CSS external entities.
9. Reduce DNS look ups.
10.Minify the Javascript components using minifying techniques.
11.As for as possible avoid redirects. This has to initiate as a new
request and hence more expensive.
12.Removing duplicate scripts. This potentially minimizes the size of the
Javascript.
13.UI pages should not have any blank spaces between the lines. This
potentially increases the size of the page. This intern affects the load
time.
14.Supply pre-compiled JSP/JSF pages and provides an option for load
on start up.
15.Configure ETags accordingly. This really helps the components are
part of the DOM. And these actions will be performed at loading of
the DOM itself. You need not wait till the page is loaded.
16.Implement appropriate caching mechanisms for read-only data.
17.Suggestible to have HTML Cache at page level not at the global JS
level. This always causes performance drawdown in terms of
backward look ups.
18.Combine CSS and Javascript files and minify the same. In fact
almost all the browsers are supporting this feature. This will save the
bandwidth time as well as load time. This will not stop the processing
stage of the DOM.
19.Optimizing the images using optimizing techniques using tools like
pngOptimizer.
20. Loading and parsing of HTML, CSS and Javascript are costly. And
hence make use of the Javascript libraries and techniques
effectively.
21. Look into the option of splitting large Javascript (any files more than
300KB) files into smaller files. This technique is very useful when the
parsing and interpretation of Javascript takes an expensive time.
22.Load the HTML/CSS/JS on demand which I call it as a lazy loading.
Again this depends on case by case. For example, rather loading JS
files at page load time, load through the scripts on demand.
23.If you look for the packages like Yahoo UI, DOJO Package, JSAN
Import, they work on the concept of lazy loading. These packages
will have direct interfaces to do lazy loading. These are applicable
for both JS and CSS.
24.Redering time best practices are,
a. Be aware of added page weight in terms of more pay load and
heavy utility logic at page level.
b. Event handlers to be attached once DOM is ready. This way
processing of DOM will not be stopped.
c. Close HTML tags explicitly to speed up the parsing. Always
implicit closed tags pose more added cost to the HTML
parsing.
d. Consider flushing the buffer at early stages itself. For
example, download of external CSS files may get a head start.
And hence it will not influence the rendering speed. This is at
rendering state level. Browsers should buffer their inputs
before displaying the same. This is very important.
e. Most DOM Operations can be accomplished before onLoad
event has fired. For example,
Window.event.onDOMReady() {
doActionSpecified();
}
f. Use Post-load Script loading which makes page load faster
and fully functional. The below snippet will be added before
</body> tag.
<script>
window.onload = function () {
var script = document.createElement("script");
script.src = /uuuu.js;
document.body.appendChild(script);
};
</script>
}
F(10);
Look up is performed every time a variable is accessed. And hence
variables will be resolves backwards from most specific to least
specific.
11.Declare and use variables in the same scope and avoid using
global variables to the reasonable extent.
12.Cache the return values from expensive look ups in the local
variables. For example,
var arr = ...;
var globalVar = 0;
(function () {
var i, l, localVar;
l = arr.length;
localVar = globalVar;
for (i = 0; i < l; i++) {
localVar++;
}
globalVar = localVar;
})();
function A () {}
A.prototype.prop1 = ...;
function B () {
this.prop2 = ...;
} B.prototype = new A();
setTimeout(function () {
// do the scheduled one.
}, 100);
var fn = (function () {
var b = false, v;
return function () {
if (!b) {
v = ...;
b = true;
}
return v;
};
})();
function fn () {
if (!fn.b) {
fn.v = ...;
fn.b = true;
}
return fn.v;
}
var i; var i;
for (i = 0; i < 100000; i++) { try {
try { for (i = 0; i < 100000;
... i++) {
} catch (e) { ...
... }
} } catch (e) {
} ...
}
26. For any branching condition like if.. else, if the branching
condition does not change, use outside the function rather
using in side of it.