How do you organize a bunch of javascripts? Pattern? MVC?

31 views
Skip to first unread message

philzi

unread,
Mar 8, 2012, 5:20:28 AM3/8/12
to phonegap
Hello there,

how do you organize all the javascripts? Are you using pattern like
MVC`(how about performance?, how to handle events?)?
I have always developed PHP and now here are my first steps with a big
javascript project.

Best regards,
Phil

WebSteve

unread,
Mar 8, 2012, 11:25:08 AM3/8/12
to phonegap
Almost all my javascripts are external files, which are referenced in
the <head> tags where appropriate.

Regards,
Steve

Kerri Shotts

unread,
Mar 8, 2012, 1:06:22 PM3/8/12
to phon...@googlegroups.com
After just trying to write out an explanation of how I'm doing things, it's clear I haven't had enough caffeine to actually /make it understandable/. Lovely.


It is under active development, and by no means should it be taken as a model of coding standards. I'm a "cobbler", so my code tends to be rather... cobbled together. Oh well -- that's my style. (Tell you what: I'll blame my C64 BASIC skills... ;-) )

Essentially, though, what I do is split everything out into html/js files. There are library js files that everything gets access to (via the index page), and then everything else is contained separately. This is only really done to prevent the misery (IMO) that is one long, big index.html that does /everything/ the app can do. As it is, one bad line of javascript is painful enough to make things break badly and silently.

Aside from the index file, every other html file is loaded with xmlhttprequest and inserted into the DOM. After that, all the script tags in them are processed as well, so they can (and do) have javascript embedded in them. This means that the UI skeleton is built in the index page, and then the content is just loaded into the appropriate places when necessary.

Performance is generally good, provided you live within the mobile device's limits: keep the fancy stuff to a minimum, essentially, and reduce tags and especially absolutely/relatively positioned elements. Do animation with css transforms, not with javascript. That kinda stuff.

Hopefully that helps some!
Reply all
Reply to author
Forward
0 new messages