Thursday, July 9, 2015

SPA Notes

This is an outline of some stuff for weaving KnockoutJS, RequireJS, and Bootstrap into a site. I'm not saying these are best practices or anything. Just my notes on what I have been doing. Mostly geared towards SPAs.

The Setup (Config) File


Notice that the JavaScript files do not have the .js extension in the config file. The shim property is used to ensure certain load orders (Bootstrap requires jQuery). The paths can be combined when loading dependencies.

The HTML File


It still needs the css files. The data-main attribute in the scripts tag tells RequireJS to get everything from that file.

Modules



It's not necessary to have a parameter for each dependency. The above module uses a bootstrap modal function, but doesn't need a variable (lines 34 and 55).

Examples of getting and posting some json are at lines 24 and 48. I use the $.ajax at 48, because it lets me specify the contentType. I ran into problems using $.post.

More to come on this...