The Effect of SharePoint 2013’s Minimal Download Strategy (MDS)
Since its inception, Vizit has been proud of its zero footprint mentality. Even when it was cool to develop in Flash, we understood that it wasn’t the right tool for the task. Well maybe it was, but it was clearly a dead end. Considering the uprising of mobile and its cold shoulder to those plugin-based technologies, the decision couldn’t have been a more correct one. Even though we don’t use Flash, we still managed to have dynamic user interfaces that work as well as a desktop app while shedding the deployment headaches that typically come along for the ride. As with any design decision, though, this one came with a trade-off: bandwidth required by application resources.
For more complicated solutions, there are some other pieces that you should investigate: window event handlers, and most painfully, the window’s unload event. First, we’ll go over window event handlers in general. Just like all of your global variables being destroyed by the garbage collector, any event handlers you’ve attached to the window object (for example, the window resize event), you’ll need to reattach after the partial page is loaded. It took some digging, but I managed to find an event deep inside the internals of the SharePoint MDS stack that fires whenever a partial page is loaded and cleanup needs to occur. Here’s a code sample for attaching to that event:
// your code here
I suggest you wrap that in a check for whether the asyncDeltaManager is available, but it might not be necessary for some deployments. In our case, we allow our code to be loaded on non-SharePoint pages where this is neither available nor needed so a simple check to see if (typeof asyncDeltaManager) is “undefined” is enough. Whenever this event fires, you can take the opportunity to re-register any events that may have been destroyed. Vizit also uses this as an opportunity to attach mouseover event listeners to any document format icons that are on the page. One great feature of our product is to display a preview of a document when the user hovers their mouse over the icon next to a given document. Without knowing the page had updated, we would stop working if MDS was enabled.
In the end, it may take some work to get your solution to operate properly in an MDS environment, but the trade-off is worth it.
Note: Some of the graphics in this post came from the MSDN article on Minimal Download Strategy which can be found here: http://msdn.microsoft.com/en-us/library/office/dn456544.aspx