OpenSocial Coding Practices

0 views
Skip to first unread message

prafulla

unread,
Jun 17, 2008, 12:22:57 AM6/17/08
to OpenSocial - OpenSocial Application Development

Hi all,

Of late, I have started building large scale applications using
Opensocial API, and I notice that my code involves lots of makeRequest
calls and many callback functions. Using all this javascript in a
single xml file might not be the best way to do it. Are there any
guidelines on :

1) how to keep the code neat and good-looking
2) ways to minimize multiple makeRequest calls

Also, I am not sure whether it is a good practice to break up my
javascript into multiple smaller files. This will improve code
readability, but I am afraid that it might increase the latency
because the application now has to access more number of files. Please
provide me your suggestions and views on this.


Thank you,
Prafulla

Aakash Bapna

unread,
Jun 17, 2008, 5:13:37 AM6/17/08
to opensoc...@googlegroups.com
Hi,
Take a look at- http://code.google.com/p/opensocial-resources/wiki/OpenSocialBestPractices
To minimize make request calls use the app's persistant data storage as much as possible.
Thanks
 
~Aakash
http://aakash-bapna.blogspot.com



> Date: Mon, 16 Jun 2008 21:22:57 -0700
> Subject: [OpenSocial] OpenSocial Coding Practices
> From: prafull...@gmail.com
> To: opensoc...@googlegroups.com

Navaneeth Krishnan

unread,
Jun 17, 2008, 9:31:51 AM6/17/08
to opensoc...@googlegroups.com

A few tips:

For (1), You could split your javascript into separate modules in your development environment. During your
build process you can concat the relevant js files and run it through a javascript/css compressor like
the YUI Compressor. The compressor strips off code comments and also does a bunch of optimizations to
give a single js file that you can use for your deployment.

You can also consider generating separate js files for your profile view and canvas view, because typically
the profile view will require much less javascript. This will ensure that you load up faster on the user profile.

(2) will depend largely on your application itself. Use cached makeRequest if you expect duplicates and,
as Aakash mentioned, the app data store, if you just want to store small amounts of data.

Hope that helps !
Navaneeth

Arne Roomann-Kurrik (Google)

unread,
Jun 19, 2008, 2:40:08 PM6/19/08
to OpenSocial - OpenSocial Application Development
This is really great advice. For a large scale app, you're going to
want to have some sort of build process that optimizes your javascript
and concatenates files, so you'll be able to structure your project
logically and then output a highly compressed single file for
production.

You can also put everything in separate files and use a PHP script to
automatically concatenate them upon request. Normally this would be a
bad idea because it could be slow, but if you instruct the container
to cache the output of the PHP script, then your server won't even
take a hit for most of the loads of your application.

~Arne


On Jun 17, 6:31 am, Navaneeth Krishnan <navaneeth.cont...@gmail.com>
wrote:
> A few tips:
> For (1), You could split your javascript into separate modules in your development environment. During your
> build process you can concat the relevant js files and run it through a javascript/css compressor likethe YUI Compressor. The compressor strips off code comments and also does a bunch of optimizations to
> give a single js file that you can use for your deployment.
> You can also consider generating separate js files for your profile view and canvas view, because typically
> the profile view will require much less javascript. This will ensure that you load up faster on the user profile.
> (2) will depend largely on your application itself. Usecached makeRequestif you expect duplicates and,
Reply all
Reply to author
Forward
0 new messages