As web applications grow larger and larger, the ability to manage the vast number of widgets within the application becomes more and more complex. In early stages of development, widgets are often initialized with one-off scripts running when the DOM has fully loaded. As the number of widgets increases, developers often find ways to avoid explicitly initializing each individual widget. However, most implementations either have shortcomings or have limitations on how additional content can be loaded on to the page.
What if widgets could be built in a way that didn't require any initialization at all? This may sound strange; how can you have a JavaScript widget without running some JavaScript to initialize it? Let's take a look at a simple pattern that has been around for a while: hijacking clicks on anchors to generate Ajax requests. The concept is simple: listen for the click event, prevent the default action, and start an Ajax request.
Your new post is loading...