Dynamically require controllers using can.route

I have a need to dynamically add/require view controllers based on the route’d page in a microsite I’m building. This is a pretty common need, User navigates to Page A, PageAController loads and then loads Page A’s view, User navigates to Page B, PageBController loads and then loads Page B’s view, and so on. While this post suggests how to approach this in a more dynamic way using canJS, this isn’t canjs specific and should apply to any framework that has a route controller.
Continue reading

Use IIFE (Immediately Invoked Function Expression)

IIFEs are an ideal solution for locally scoping global variables/properties and protecting your JavaScript codebase from outside interference (e.g. third-party libraries). If you are writing jQuery code that will be run in many different environments (e.g. jQuery plugins), then it is important to use an IIFE to locally scope jQuery because you can’t assume everyone is using the $ to alias jQuery.
Continue reading