Here are some tips and tricks to keep in mind, when developing gadgets.
In our sample gadget developed so far errors are not handled. For example, what would happen if the content from URL is not fetched due to a network outage? As of now, we display an empty gadget. It is recommended to display a meaningful error to the userusing a simple try/catch block as follows:
Like we did in this tutorial, it is a good practice to start small and incrementally keep on building the gadget, step by step, testing along the way. Incremental testing is key to success. It allows you space to back track and recollect on what went wrong and fix those. If we are to take big steps, it would be harder to pinpoint problem cases.
When Things Go Wrong: F12
When things are not working, the best way to debug is to use developer tools offered by the browsers. The function key F12 brings up the developer tools in both Chrome and Internet Explorer. The console of the developer tools leads you to the errors and error locations easily.
In addition to developer tools, the "Inspect element" option you get on the right click pop-up on Chrome Web browser is quite handy. It is paarticularly helpful when you know where in the gadget content is supposed to appear yet does not.
Always Test with IE
Quite often, if it works in IE, chances are high it works in other browsers. Since you are developing for a large audience, it is important to consider cross-browser compatibility. If you plan to open up the gadgets for a wider audience, it is important to use IE as part of the incremental test efforts. In other words, test with IE while you are developing, rather than trying to test the finished gadget with IE.
Use an IDE
Even simple things like indentation help a great deal when you are developing a fairly complex gadget. Using an IDE is a best practice. You can see how WSO2 Carbon Studio can help you develop gadgets from scratch in tutorial How to Creat Gadgets Using Carbon Studio.