If the data is known at the point the page is rendered then adding a script to create your data or setting json via a literal or similar or other variation are perfectly reasonable.
My thanks go out to Marco of zingzing. Most of the techniques involve common sense once you have understood the underlying problem. Avoid interaction with host objects Watch out for these guys.
Repeated interaction with them will kill your performance. CSS3 Transitions have been around for a while now, so there are few excuses not to use them. You can even use a polyfill if you are worried about older browsers.
Use fast DOM traversal with document. Given the availability of jQuery, it is now easier than ever to produce highly specific selectors based on a combination of tag names, classes and CSS3. You need to be aware that this approach involves several iterations while jQuery loops thorough each subset of DOM elements and tries to find a match.
Use this technique to reduce DOM traversal trips by storing references to browser objects during instantiation for later usage. For example, if you are not expecting your DOM to change you should store a reference to DOM or jQuery objects you are going to use when your page is created; if you are building a DOM structure such as a dialog window, make sure you store a few handy reference to DOM objects inside it during instantiation, so you dont need to find the same DOM object over an over again when a user clicks on something or drags the dialog window.
Batch your DOM changes, especially when updating styles. When making calls to modify DOM make sure you batch them up so as to avoid repeated screen rendering, for example when applying styling changes. The ideal approach here is to make many styling changes in one go by adding or removing a class, rather than apply each individual style separately.
This is because every DOM change prompts the browser to re-render the whole UI using the boxing model. See these examples in jQuery: This is an extension of the fourth point above Keep HTML super-leanyou can use this technique to remove items from DOM that are not being visually rendered on screen, such as the area outside the viewport of a scrollable DIV, and append the nodes again when they are needed.
This will reduce memory usage and DOM traversal speeds.
This is particularly bad for mobile users who have limited bandwidth capacity. Actively manage and reduce dependency payload in your code. Write code that reduces library dependencies to an absolute minimum. Use this approach to reduce the number of libraries your code requires to a minimum, ideally to none, thus creating an incredible boost to the loading times required for your page.
You can reduce dependency on external libraries by making use of as much in-browser technology as you can, for example you can use document. If you need complex CSS selectors use Sizzle.
Also, before adding any new library to the codebase, evaluate whether or you really need it.
Perhaps you are just after 1 single feature in the whole library? Minimize and combine your code into modules. The logic here is that a single minimized request for a 10Kb. Use a post-load dependency manager for your libraries and modules. Much of your functionality will not need to be implemented until after the page loads.
However, I notice that this is only done when there is a full page postback. How to open a new window in urbanagricultureinitiative.com# code behind without full page postback.
Also consider if the RegisterStartupScript method is a better fit for what you want to do.